-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue-entire-file-to-tumblr.py
executable file
·74 lines (53 loc) · 2.05 KB
/
queue-entire-file-to-tumblr.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
72
73
74
#!/usr/bin/env python
# coding=utf-8
from __future__ import division
import os, sys, glob
import random
import pprint
import time
import tumblpy
import markov
import tumblr_auth_tokens
from utils import *
#-------------------------------------------------------------------------------------------
#--- COMMAND LINE
HELP = """
tumblr-queue-entire-file.py file.txt
Sends the entire file to Tumblr, making one text post in the queue for each line in the file.
Leaves the original file unchanged.
"""
ARGS = sys.argv[1:]
if '-h' in ARGS or len(ARGS) != 1:
print
print HELP
print
sys.exit(0)
FILENAME = ARGS[0]
#-------------------------------------------------------------------------------------------
#--- TUMBLR SETUP
t = tumblpy.Tumblpy(app_key = tumblr_auth_tokens.TUMBLR_CONSUMER_KEY,
app_secret = tumblr_auth_tokens.TUMBLR_CONSUMER_SECRET,
oauth_token = tumblr_auth_tokens.TUMBLR_OAUTH_TOKEN,
oauth_token_secret = tumblr_auth_tokens.TUMBLR_OAUTH_TOKEN_SECRET)
tumblrUrl = 'http://%s.tumblr.com'%(tumblr_auth_tokens.TUMBLR_USERNAME.replace('_','-'))
#-------------------------------------------------------------------------------------------
#--- MAIN
if __name__ == '__main__':
print '---------------------------------------------------------------------------------\\'
for ii,line in enumerate(file(FILENAME,'r').readlines()):
line = line.strip()
if not line:
continue
print 'posting %s: "%s"...'%(ii,line)
post = t.post( 'post',
blog_url=tumblrUrl,
params=dict(type='text',
state='queue',
title=line,
body='',
source_url=tumblrUrl,
source_title=tumblrUrl,
)
)
print '---------------------------------------------------------------------------------/'
#