Skip to content

Instantly share code, notes, and snippets.

@gszathmari
Last active September 16, 2015 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gszathmari/bd7123b76374a0d74288 to your computer and use it in GitHub Desktop.
Save gszathmari/bd7123b76374a0d74288 to your computer and use it in GitHub Desktop.
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
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)
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