forked from Unthinkingbit/charity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widen.py
84 lines (67 loc) · 2.63 KB
/
widen.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
84
"""
Wikicopy is a program to download the articles of a dokuwiki and save them in a zip file.
==Commands==
===Help===
The -h option, the -help option, will print the help, which is this document. The example follows:
python account.py -h
===Input===
Default is http://devtome.com
The -input option sets the input file name. The example follows:
python wikicopy.py -input http://devtome.com
==Install==
For wikicopy to run, you need Python 2.x, wikicopy will probably not run with python 3.x. To check if it is on your machine, in a terminal type:
python
If python 2.x is not on your machine, download the latest python 2.x, which is available from:
http://www.python.org/download/
"""
import almoner
import devtome
import os
import shutil
import sys
__license__ = 'MIT'
def writeOutput(arguments):
'Write output.'
if '-h' in arguments or '-help' in arguments:
print(__doc__)
return
folderName = almoner.getParameter(arguments, 'widen', 'folder')
peerRootAddress = almoner.getParameter(arguments, 'http://galaxies.mygamesonline.org/receiver.csv', 'input')
round = int(almoner.getParameter(arguments, '23', 'round'))
writeFolder(folderName, peerRootAddress, round)
def writeFolder(folderName, peerRootAddress, round):
'Write zip file.'
print('Making directory:')
print(folderName)
print('')
almoner.makeDirectory(folderName)
peerAddress = almoner.getSuffixedFileName(peerRootAddress, str(round))
print('Getting peer:')
print(peerAddress)
print('')
peerText = almoner.getLocationText(peerAddress)
peerTextUntilCoins = peerText[: peerText.find('_begincoins')]
unthinkingbitString = 'https://raw.github.com/Unthinkingbit/charity/master/receiver.csv'
fuzzyString = 'http://devcoinpool.btc-music.com/receiver/receiver.csv'
peerTextUntilCoins = peerTextUntilCoins.replace(unthinkingbitString, fuzzyString)
print('Peer text until coins:')
print(peerTextUntilCoins)
print('')
print('Writing widened files:')
for widenRound in xrange(round + 1):
writeWidenedFile(folderName, peerRootAddress, peerTextUntilCoins, widenRound)
print('')
def writeWidenedFile(folderName, peerRootAddress, peerTextUntilCoins, widenRound):
'Write widened file.'
title = almoner.getSuffixedFileName('receiver.csv', str(widenRound))
widenPath = os.path.join(folderName, title)
receiverAddress = almoner.getSuffixedFileName(peerRootAddress, str(widenRound))
receiverText = almoner.getLocationText(receiverAddress)
receiverTextFromCoins = receiverText[receiverText.find('_begincoins') :]
widenText = peerTextUntilCoins + receiverTextFromCoins
almoner.writeFileText(widenPath, widenText)
def main():
'Write output.'
writeOutput(sys.argv)
if __name__ == '__main__':
main()