chir.py- twitter bot that earns bitcoin via ppc links |
git clone git://git.acid.vegas/chir.py.git |
Log | Files | Refs | Archive | README | LICENSE |
functions.py (2127B)
1 #!/usr/bin/env python 2 # Chir.py Twitter Bot - Developed by acidvegas in Python (https://acid.vegas/chir.py) 3 # functions.py 4 5 import random 6 import re 7 import urllib.request 8 9 import feedparser 10 11 import config 12 import debug 13 14 def coinurl(url): 15 source = urllib.request.urlopen('https://coinurl.com/api.php?uuid=%s&url=%s' % (config.coinurl_uuid, url)) 16 charset = source.headers.get_content_charset() 17 if charset : return source.read().decode(charset) 18 else : return source.read().decode() 19 20 def get_news(): # This is very sloppy and needs some work. 21 news_list = list() 22 sport = random.choice(list(config.news_feeds.keys())) 23 sport_news = feedparser.parse(config.news_feeds[sport]) 24 sport_keywords = config.news_keywords[sport] 25 for item in sport_news.entries: 26 description = strip_html(item.summary) 27 if ') -- ' in description: 28 cutoff = description.split(') -- ')[0] 29 description = description.split(cutoff)[1] 30 if ') - ' in description: 31 cutoff = description.split(') - ')[0] 32 description = description.split(cutoff)[1] 33 description = description.replace('*', '') 34 description = description.replace('\'', '') 35 description = description.replace('"', '') 36 description = description.replace('--', '-') 37 description = description.replace(' ', ' ') 38 for word in sport_keywords: 39 if word in description.lower(): 40 description = re.sub(word, '#' + word, description, flags=re.IGNORECASE) 41 if len(description) > 118: 42 description = description[:118] 43 split = description.split() 44 description = description.split(split[len(split)-1])[0][:-1] + '... ' 45 try: 46 link = coinurl(item.link) 47 except Exception as ex: 48 debug.error('Error occured creating PPC link!', ex) 49 else: 50 description = description + ' ' + link 51 news_list.append(description) 52 return news_list 53 54 def strip_html(source): 55 return re.compile(r'<.*?>').sub('', source)