gdritter repos lib-static / 6a951a0
Added standard utils Getty Ritter 9 years ago
3 changed file(s) with 111 addition(s) and 0 deletion(s). Collapse all Expand all
1 #!/usr/bin/python2
2
3 import json
4 import os
5 import subprocess
6 import sys
7 import time
8 import uuid
9
10 repo = os.getenv('LIB_REPO') or \
11 os.getenv('HOME') + '/projects/lib-data'
12 os.chdir(repo)
13
14 for url in sys.argv[1:]:
15 r = {}
16 new_id = uuid.uuid4()
17 r['url'] = url
18 r['id'] = str(new_id)
19
20 new_file = repo + '/links/' + str(new_id)
21 with open(new_file, 'w') as f:
22 json.dump(r, f)
23
24 subprocess.call(['git', 'add', new_file]) and \
25 sys.stderr.write('Unable to add new file')
26
27 if sys.argv[1:]:
28 msg = 'New link(s) added at {0}'.format(
29 time.strftime('%Y-%m-%d/%H-%M', time.localtime()))
30 subprocess.call(['git', 'commit', '-m', msg]) and \
31 sys.stderr.write('Unable to commit new file')
32 subprocess.call(['git', 'push']) and \
33 sys.stderr.write('Unable to push')
34 sys.stdout.write('Successful!\n')
1 #!/usr/bin/python2
2
3 import json
4 import os
5 import subprocess
6 import sys
7 import time
8 import yaml
9 import uuid
10
11 repo = os.getenv('LIB_REPO') or \
12 os.getenv('HOME') + '/projects/lib-data'
13
14 def ensure(obj, key):
15 if key not in obj:
16 sys.stderr.write('Missing `{0}` field'.format(key))
17 sys.exit(1)
18
19 r = yaml.load(sys.stdin.read())
20 ensure(r, 'content')
21 new_id = uuid.uuid4()
22 r['id'] = str(new_id)
23
24 new_file = repo + '/quips/' + str(new_id)
25 with open(new_file, 'w') as f:
26 json.dump(r, f)
27
28 msg = 'New quip added at {0}'.format(
29 time.strftime('%Y-%m-%d/%H-%M', time.localtime()))
30
31 os.chdir(repo)
32 subprocess.call(['git', 'add', new_file]) and \
33 sys.stderr.write('Unable to add new file')
34 subprocess.call(['git', 'commit', '-m', msg]) and \
35 sys.stderr.write('Unable to commit new file')
36 subprocess.call(['git', 'push']) and \
37 sys.stderr.write('Unable to push')
38 sys.stdout.write('Successful!\n')
1 #!/usr/bin/python2
2
3 import json
4 import os
5 import subprocess
6 import sys
7 import time
8 import yaml
9 import uuid
10
11 repo = os.getenv('LIB_REPO') or \
12 os.getenv('HOME') + '/projects/lib-data'
13
14 def ensure(obj, key):
15 if key not in obj:
16 sys.stderr.write('Missing `{0}` field'.format(key))
17 sys.exit(1)
18
19 r = yaml.load(sys.stdin.read())
20 ensure(r, 'content')
21 ensure(r, 'author')
22 new_id = uuid.uuid4()
23 r['id'] = str(new_id)
24
25 new_file = repo + '/quotes/' + str(new_id)
26 with open(new_file, 'w') as f:
27 json.dump(r, f)
28
29 msg = 'New quote added at {0}'.format(
30 time.strftime('%Y-%m-%d/%H-%M', time.localtime()))
31
32 os.chdir(repo)
33 subprocess.call(['git', 'add', new_file]) and \
34 sys.stderr.write('Unable to add new file')
35 subprocess.call(['git', 'commit', '-m', msg]) and \
36 sys.stderr.write('Unable to commit new file')
37 subprocess.call(['git', 'push']) and \
38 sys.stderr.write('Unable to push')
39 sys.stdout.write('Successful!\n')