-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwitterbot.py
executable file
·41 lines (30 loc) · 1.09 KB
/
twitterbot.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
import sys, os, random, glob, codecs
from twython import Twython,TwythonError
_consumer_key = ''
_consumer_secret = ''
_access_token = ''
_access_token_secret = ''
_location = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
_api = Twython(_consumer_key, _consumer_secret, _access_token, _access_token_secret)
_working_folder = '/home/alarm/DMS/sync'
_hashtag = '#DISARMnado'
def randomtweet():
try:
_randfile = random.choice(glob.glob1(_working_folder, '*.txt'))
if _randfile[0:3] == 'Map':
return None
_format, _ttl, _type, _source, _destination, _lat, _long, _datetime, _group = _randfile.split('_')
_tweetsfile = codecs.open(os.path.join(_location, _working_folder, _randfile), encoding='utf-8', mode='r')
_tweetscontents = _tweetsfile.read()
_tweetsfile.close()
_status = _hashtag + ' ' + _source + ' ' + _lat + ' ' + _long + ' ' + _datetime + ' ' + _tweetscontents[:70]
print(_status)
_api.update_status(status=_status)
return None
except TwythonError:
return None
except IndexError:
return None
except IOError:
return None
randomtweet()