-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostInfo_now.py
More file actions
70 lines (52 loc) · 1.75 KB
/
postInfo_now.py
File metadata and controls
70 lines (52 loc) · 1.75 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
import argparse
import tweepy
from datetime import datetime, date, timedelta
import time
import imp
#import configSettings_ppe
def GetArgs():
parser = argparse.ArgumentParser(description=__file__)
parser.add_argument('--config', help='directory for config file')
parser.add_argument('--tweet', help='text to tweet')
parser.add_argument('--hash', nargs='+', help='hashtags: text only (no symbols), space separated')
args = parser.parse_args()
print "args:",args
argDict={'config':"../configs/configSettings_ppe.py", 'tweet':"testText" }
for a in vars(args).iteritems():
if not a[1]==None:
print "got argument",a
try:
argDict[a[0]]=int(a[1])
except:
argDict[a[0]]=a[1]
return argDict
######################
### useful functions
######################
def postInfo(tweet, configPath):
print "string to tweet:\n"+tweet
#sys.path.insert(0, "../configs")
#import configSettings_ppe as configSettings
configSettings = imp.load_source('something', configPath)
api=configSettings.get_api()
tweet = str(tweet)+" at:"+str(datetime.now()) # add time to avoid repeated tweets
status = api.update_status(status=tweet)
print "...tweeted"
# Yes, tweet is called 'status' rather confusing
######################
### main
######################
def main():
argDict=GetArgs()
tweetStr=argDict['tweet']
for h in argDict['hash']:
tweetStr+=" #"+str(h)
postInfo(tweetStr, argDict['config'])
if __name__ == "__main__":
print "### in",__file__,"###"
start = time.time()
main()
end = time.time()
print "\n+++ Total scan time: ",(end-start),"seconds +++\n"
print "### out",__file__,"###"
#some values to post