-
Notifications
You must be signed in to change notification settings - Fork 1
/
publishBlog.py
executable file
·83 lines (71 loc) · 2.5 KB
/
publishBlog.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
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import os, time
import configparser
import moduleXmlrpc
# https://github.com/fernand0/scripts/blob/master/moduleXmlrpc.py
from configMod import *
def archive(blogId, blogName, blogUrl, text, postId):
theTime = time.localtime(time.time())
path = os.path.join(os.path.expanduser('~') , 'Documents/www/archivo')
path = '%s/%s/%s'%(path,blogId,time.strftime("%Y/%m", theTime))
if not os.path.isdir(path):
os.makedirs(path)
fileName = '%s/historia-%s'%(path,time.strftime("%Y%m%d%H%M%S",theTime))
#fileName = '%s/%s/historia-%s'%(path,blogId,time.strftime("%Y%m%d%H%M%S",time.localtime(time.time())))
fPost = open(fileName,'w')
fPost.write(text)
fPost.write('\n Dónde:')
fPost.write(blogName)
fPost.write('\n URL:')
fPost.write(blogUrl)
fPost.write('/historias/')
fPost.write(str(postId))
fPost.write('\n')
fPost.close()
print('Historia guardada en %s' % fileName)
return fileName, blogUrl[:-1]+'.blogalia.com/historias/'+str(postId)
def post():
f = open('historia', "r")
title = f.readline().strip()
text = title
title = title.encode('ascii', 'xmlcharrefreplace')
body = f.read()
text = text + '\n' + body
body = body.encode('ascii', 'xmlcharrefreplace')
return(title, body, text)
def main():
selOp = input ("""
Choose one:
u)pdate post
n)ew post
d)delete post
-> """)
print("You have chosen ", selOp)
config = configparser.ConfigParser()
config.read(CONFIGDIR + '/.rssBlogs')
blog = moduleXmlrpc.moduleXmlrpc()
section = config.sections()[1]
url = config.get(section, "url")
rpc = config.get(section, "xmlrpc")
print(url+rpc)
blog.setUrl(url)
blog.setXmlRpc()
if selOp == 'u':
print("Updating ... %s\n"% blog.getUrl())
title, postId = blog.selectPost()
title, body, text = post()
print(postId,type(postId))
postId = blog.editPost(postId, title, body)
fileName, theUrl = archive(blog.Id, blog.name, blog.url, text, postId)
elif (selOp == 'n'):
print("Sending ... %s\n"% blog.getUrl())
title, body, text = post()
postId = blog.newPost(title, body)
#postId = '12345'
fileName, theUrl = archive(blog.Id, blog.name, blog.url, text, postId)
elif (selOp == 'd'):
print("Deleting ... %s\n"% blog.getUrl())
title, postId = blog.selectPost()
blog.deletePost(postId)
if (__name__ == '__main__'):
main()