Last active
July 27, 2016 20:08
-
-
Save Ohcanep/9f774117558de190f90e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# curl -sS $KARINKEIKAT_BASE_URL/$(date +%Y)'.json?orderBy="date"&startAt="'$(date -I)'"&limitToFirst=5' | jq '.' | |
import json | |
import os | |
from sys import argv | |
import lxml.html | |
import requests | |
page = requests.get('http://www.karipeitsamo.com/etusivu.htm') | |
tree = lxml.html.fromstring(page.text) | |
tr_list = tree.xpath('//table//table/tr') | |
# the first and last <tr>s are empty and the second <tr> holds the year | |
year = tr_list[1][0].text | |
tr_list = tr_list[2:-1] | |
gigs = dict() | |
for i, tr in enumerate(tr_list): | |
day = tr[0].text[:2] | |
month = tr[0].text[3:5] | |
gigs['{0:03d}'.format(i + 1)] = { | |
'date': '{}-{}-{}'.format(year, month, day), | |
'venue': tr[1].text | |
} | |
gigs_json = json.dumps(gigs, sort_keys=True) | |
print(gigs_json) | |
if len(argv) == 2 and argv[1] in ['patch', 'put']: | |
base_url = os.environ['KARINKEIKAT_BASE_URL'] | |
secret = os.environ['KARINKEIKAT_SECRET'] | |
endpoint = '{}/{}.json?auth={}'.format(base_url, year, secret) | |
verb = argv[1] | |
if verb == 'patch': | |
requests.patch(endpoint, gigs_json) | |
elif verb == 'put': | |
requests.put(endpoint, gigs_json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": { | |
".read": true, | |
".write": false, | |
"$year": { | |
".indexOn": "date", | |
"date": { ".validate": "newData.isString() && newData.val().matches(/^(19|20)[0-9][0-9]-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$/)" }, | |
"venue": { ".validate": "newData.isString()" }, | |
"$other": { ".validate": false } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment