-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulator.py
57 lines (44 loc) · 1.29 KB
/
simulator.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
53
54
55
56
57
# -*- coding: utf-8 -*-
import crawler, twitter, time, database, requests
def main():
url = 'http://vg.no'
keywords = ['snegl',
'kropp',
'dette',
'paradise',
'pladask',
'miss universe',
'frøken norge',
'sex',
'triks',
'pokemon',
'undertøy',
'hollywood',
'kjendis',
'øvelse',
'slik',
'slank',
'digg'
]
old_posts = database.get_posts()
try:
new_posts = crawler.crawl(url, keywords)
new = 0
for k,v in new_posts.items():
if k not in old_posts.keys():
title = v['title'].encode('utf-8')
print 'POSTING' , title
print twitter.post_status(title)
database.add_post(k, v)
new += 1
time.sleep(1)
if new == 0:
print 'no new posts found'
elif new == 1:
print 'one new post found'
else:
print str(new) + ' new posts found'
except requests.exceptions.ConnectionError:
print 'could not connect'
if __name__=='__main__':
main()