/[ascend]/trunk/tools/mediawiki/html2mediawiki/upload.py
ViewVC logotype

Contents of /trunk/tools/mediawiki/html2mediawiki/upload.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2198 - (show annotations) (download) (as text)
Thu May 13 14:21:03 2010 UTC (12 years, 3 months ago) by jpye
File MIME type: text/x-python
File size: 1811 byte(s)
Upload
1 #!/usr/bin/env python
2 # This script will do the hard work of uploading the content to our wiki.
3 import sys
4 import urllib2
5 import os.path
6 import pickle
7
8 res = pickle.load(open("reslist.pickle"))
9
10 wiki = "http://ascend.cheme.cmu.edu/"
11
12 # first create a big huge textfile containing the pages
13
14 if 0:
15 pagestart = "\nPAGESTARTxkljhdakljfdfsljhkjhdsgnsdgnweisdwgwrehjgsjfs\n"
16 pageend = "\nPAGEENDslkfjsldkfjskldfjskljfsghwuewrweorswnmbrwewemwr\n"
17 titlestart = "TITLESTART>>>"
18 titleend = "<<<TITLEEND\n"
19 print "WRITING PAGES TO BIG TEXT FILE"
20 f = open('bigpage.txt','w')
21 for name in res:
22 filename,status = res[name]
23 f.write(pagestart)
24 f.write(titlestart + name + titleend)
25 f.write(open(filename).read())
26 f.write(pageend)
27 f.close()
28
29 print "PAGES WRITTEN"
30
31 sys.path.append(os.path.expanduser("~/pywikipedia"))
32 import pagefromfile
33 import codecs
34
35 print "UPLOADING TO WIKI"
36
37 errorfile = None
38 # TODO: make config variables for these.
39 filename = "bigpage.txt"
40
41 include = False
42 force = True
43 append = None
44 notitle = True
45 summary = "Restored page from Google Cache, uploaded by John Pye"
46 minor = False
47 autosummary = False
48 dry = False
49
50 bot = pagefromfile.PageFromFileRobot(None, force, append, summary, minor, autosummary, dry)
51
52 try:
53 for name in res:
54 filename,status = res[name]
55 if status !="SAVED" and status !="ERROR":
56 content = codecs.open(filename,'r','utf-8').read()
57 errrorfile = name
58 try:
59 bot.put(name,content)
60 errorfile = None
61 res[name] = (filename,"SAVED")
62 except Exception,e:
63 print "ERROR in uploading:",e
64 if errorfile:
65 filename,status=res[errorfile]
66 res[errorfile]=(filename,"ERROR")
67
68 except Exception,e:
69 print "ERROR:",str(e)
70 except KeyboardInterrupt:
71 print "INTERRUPTED"
72
73 pickle.dump(res,open("reslist.pickle","w"))
74 print "STATUS FILE UPDATED"
75

Properties

Name Value
svn:executable *

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22