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
|
#!/usr/bin/env python3
import os
import subprocess
import sys
import requests
base_url = 'https://etherpad.wikimedia.org/p'
savedir = os.path.expanduser('~/wmf/etherpads')
def load_names(filename):
return open(filename).read().splitlines()
def pad_url(base_url, name):
return '{}/{}/export/txt'.format(base_url, name)
def get_pad(url):
r = requests.get(url)
if not r.ok:
raise Exception(
'Failed to GET {}: {} {}'.format(url, r.status_code, r.text))
return r.text
def save_text(savedir, name, text):
with open(os.path.join(savedir, name), 'w') as f:
f.write(text)
for filename in sys.argv[1:]:
names = load_names(filename)
for name in names:
url = pad_url(base_url, name)
text = get_pad(url)
save_text(savedir, name, text)
output = subprocess.check_output(
['git', 'status', '--porcelain'], cwd=savedir)
if output:
subprocess.check_call(['git', 'add', '.'], cwd=savedir)
subprocess.call(['git', 'commit', '-qm', 'Autoadd', '.'], cwd=savedir)
print('OK. Added new and changed files to git.')
else:
print('OK. Nothing to do.')
|