Last active
September 16, 2015 17:04
-
-
Save gszathmari/bd7123b76374a0d74288 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
at | |
bu | |
bc | |
bg | |
ch | |
cy | |
de | |
eg | |
fg | |
gp | |
hr | |
kc | |
ks | |
la | |
ln | |
lv | |
me | |
mr | |
nb | |
nj | |
nk | |
nz | |
pp | |
rg | |
sa | |
si | |
sz | |
tr | |
uk | |
ur | |
vn | |
wb |
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
import requests | |
import codecs | |
from bs4 import BeautifulSoup | |
from slugify import slugify | |
import json | |
def get_networks(domain): | |
results = [] | |
payload = {'domains': domain} | |
baseurl = 'http://nextbike.net/maps/nextbike-live.xml' | |
r = requests.get(baseurl, params=payload) | |
soup = BeautifulSoup(r.text, "lxml") | |
country = soup.find('country') | |
for city in soup.findAll('city'): | |
network = {} | |
network['domain'] = domain | |
if "nextbike" in country['name']: | |
name = "nextbike-" + city['name'] | |
else: | |
name = country['name'] + '-' + city['name'] | |
network['tag'] = slugify(name) | |
network['meta'] = {} | |
network['meta']['name'] = country['name'] | |
network['meta']['latitude'] = float(city['lat']) | |
network['meta']['longitude'] = float(city['lng']) | |
network['meta']['city'] = city['name'] | |
network['meta']['country'] = country['country'] | |
network['city_uid'] = city['uid'] | |
results.append(network) | |
return results | |
if __name__ == "__main__": | |
results = [] | |
domains = [line.rstrip('\n') for line in open('input.txt')] | |
for domain in domains: | |
print("Processing %s" % domain) | |
for result in get_networks(domain): | |
results.append(result) | |
data = json.dumps({'instances': sorted(results)}, ensure_ascii=False, indent=4, separators=(',', ': ')).encode('utf8') | |
print(data) |
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
Unidecode==0.04.18 | |
argparse==1.2.1 | |
beautifulsoup4==4.4.0 | |
lxml==3.4.4 | |
python-slugify==1.1.3 | |
requests==2.7.0 | |
wsgiref==0.1.2 | |
xmlutils==1.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment