Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
removed bitly, some refoctor
Browse files Browse the repository at this point in the history
  • Loading branch information
pyprism committed May 11, 2016
1 parent 924a7e0 commit da72724
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions news/hn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,11 @@
import django
import os
import re
import requests

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hiren.settings")
django.setup()

from news.models import Bunny, Tag
from hiren.settings import JSON_DATA


def bitly(url):
"""
Call Bit.ly api
:return: the fu$king short url
"""
payload = {'access_token': JSON_DATA['bitly_access_token'], 'longUrl': url, 'format': 'txt'}
response = requests.get('https://api-ssl.bitly.com/v3/shorten', params=payload)
return response.text


def rss():
Expand All @@ -30,22 +18,19 @@ def rss():
tags = Tag.objects.all()
bunny = feedparser.parse('https://news.ycombinator.com/rss')
for i in bunny.entries:
duplicate = Bunny.objects.filter(comment_url=i.comments)
if duplicate.exists() is False:
if Bunny.objects.filter(comment_url=i.comments).exists() is False:
_hash = ''
post = {'message': '', 'link': ''}
for bunny in tags: # search for predefined value in post title
if re.findall('\\b' + bunny.name + '\\b', i.title_detail.value, re.I):
_hash = _hash + ' #' + bunny.name
if len(_hash): # if _hash has value append to end of the post
link = bitly(i.link)
post['message'] = i.title_detail.value + ' : ' + link + _hash + " " + "Comments: " + bitly(i.comments)
post['link'] = link
post['message'] = i.title_detail.value + ' : ' + i.link + _hash + " " + "Comments: " + i.comments
post['link'] = i.link
feed.append(post)
else:
link = bitly(i.link)
post['message'] = i.title_detail.value + ' : ' + link + " " + "Comments: " + bitly(i.comments)
post['link'] = link
post['message'] = i.title_detail.value + ' : ' + i.link + " " + "Comments: " + i.comments
post['link'] = i.link
feed.append(post)
Bunny(comment_url=i.comments).save()
return feed

0 comments on commit da72724

Please sign in to comment.