-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.py
executable file
·71 lines (54 loc) · 1.8 KB
/
post.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver
from photo2tumblr import TumblrAPIv2, APIError
import time
import os
import sys
import configparser
def screenshot( url, config ):
display = Display( visible=0, size=( config['SCREEN']['WIDTH'], config['SCREEN']['HEIGHT'] ) )
display.start()
browser = webdriver.Firefox()
browser.get( url )
browser.save_screenshot( 'screenie.png' )
browser.quit()
display.stop()
def post ( config ):
api = TumblrAPIv2( config['DEFAULT']['CONSUMER_KEY'], \
config['DEFAULT']['CONSUMER_SECRET'], \
config['DEFAULT']['OAUTH_TOKEN'], \
config['DEFAULT']['OAUTH_TOKEN_SECRET'] )
date = time.gmtime(os.path.getmtime('./screenie.png'))
post = {
'type' : 'photo',
'date' : time.strftime ("%Y-%m-%d %H:%M:%S", date),
'data' : './screenie.png',
'tags' : time.strftime ("%Y", date) + ", photo",
'caption' : time.strftime ("%B %d / %Y", date)
}
try:
response = api.createPhotoPost( config['DEFAULT']['BLOG'], post)
if 'id' in response:
print response['id']
else:
print response
except APIError:
print "Error Uploading file!"
finally:
os.remove('./screenie.png')
def main( url ):
# Keys in http://www.tumblr.com/oauth/apps
config = configparser.ConfigParser()
config.read( 'config.ini' )
print "Taking screenshot ..."
screenshot ( url, config )
print "Done!"
print "Now posting to %s ..." % config['DEFAULT']['BLOG']
post ( config )
print "Done! "
if __name__ == "__main__":
if len (sys.argv) > 1 :
main( sys.argv[1] )
else:
print "Usage: post.py <<url_to_fetch>>\n"