-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathone.py
52 lines (42 loc) · 1.89 KB
/
one.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from TwitterSearch import *
import time
import datetime
from jinja2 import Template, Environment, FileSystemLoader
import os
import pdfkit
from slugify import slugify
from keys import *
data=[]
client = "Ford Smart Journey"
#keywords = ['multitouch.devpost.com', 'j.mp/1QMGD4k', 'Multi-Touch Multi-Hack']
keywords = ['#FordMxSmartJourney', 'j.mp/1T7uZCi', 'ford smart journey', 'fordsmartjourney.devpost.com']
#keywords = ['#IntelligentWorld','intelligentworld.devpost.com', 'j.mp/1SiGFrN']
#keywords = ['j.mp/22iwfJF', '#SparkBizApps', 'apachespark.devpost.com']
# jinja stuff
css = "pdf.css"
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
def toHTML(data, client):
fn = slugify(client + " "+ datetime.date.today().strftime('%m/%d/%y'))
jenv = Environment(loader=FileSystemLoader(THIS_DIR), trim_blocks=True)
tmpl = jenv.get_template('template.html')
out = tmpl.render(data=data, client=client)
with open('reports/'+fn+'.html', "wb") as fh:
fh.write(out.encode('utf-8'))
pdfkit.from_string(out, 'reports/'+fn+'.pdf', css=css)
try:
ts = TwitterSearch(
consumer_key = ck,
consumer_secret = cs,
access_token = at,
access_token_secret = ast
)
tso = TwitterSearchOrder()
tso.set_keywords(keywords, or_operator=True)
for tweet in ts.search_tweets_iterable(tso):
ts = time.strftime('%m-%d-%y %H:%M', time.strptime(tweet['created_at'],'%a %b %d %H:%M:%S +0000 %Y'))
# print( '[%s] @%s tweeted: %s, http://twitter.com/statuses/%s, RT: %s\n' % ( ts, tweet['user']['screen_name'], tweet['text'], tweet['id'], tweet['retweet_count']) )
data.append({'date': ts, 'text': tweet['text'], 'avatar': tweet['user']['profile_image_url_https'], 'user': tweet['user']['screen_name'], 'id': tweet['id'], 'rt': tweet['retweet_count']})
#print data
toHTML(data, client)
except TwitterSearchException as e:
print(e)