예제 #1
0
def load_countries():
    property_list = ('name', 'tld', 'abbr' 'phone', 'curr_code', 'curr_name')
    countries = dict()
    with open('./data/countries/country-by-abbreviation.json') as json_file:
        for line in yaml.safe_load(json_file):
            country = dict([('name', line['country']),
                            ('abbr', line['abbreviation'])])
            countries[line['country']] = country

    with open('./data/countries/country-by-domain-tld.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['tld'] is None:
                    country['tld'] = line['tld'][1:]

    with open('./data/countries/country-by-currency-code.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['currency_code'] is None:
                    country['curr_code'] = line['currency_code']

    with open('./data/countries/country-by-currency-name.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['currency_name'] is None:
                    country['curr_name'] = line['currency_name']

    with open('./data/countries/country-by-calling-code.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['calling_code'] is None:
                    country['phone'] = line['calling_code']

    start_db()

    for k, v in countries.items():
        country = Country(name=v['name'])
        if 'tld' in v:
            country.tld = v['tld']
        if 'abbr' in v:
            country.abbr = v['abbr']
        if 'phone' in v:
            country.phone = v['phone']
        country.save()

    stop_db()

    print(json.dumps(countries, indent=4, sort_keys=True))
예제 #2
0
def route_test(trip):
    _, Session = start_db(os.environ["DATABASE_URL"])
    time = trip["start_time"]
    for leg in trip["legs"]:
        time = end_time(Session(), time, leg)
        time += timedelta(minutes=1)  # assume all in station transfers take 1 minute
    return time - trip["start_time"]
예제 #3
0
from flask import Flask
from flask.logging import default_handler
import logging
from logging.config import dictConfig
from config import LOGGING
from models import start_db

dictConfig(LOGGING)
app = Flask(__name__)

app.logger = logging.getLogger('CurrencyMain')
app.logger.removeHandler(default_handler)

start_db()

import views
예제 #4
0
def scrape_range(start_date=START_DATE, end_date=END_DATE):
    _, Session = start_db(os.environ["DATABASE_URL"])
    for date in daterange(start_date, end_date):
        scrape_date(date, Session(), requests_session())
예제 #5
0
def test_db_load():
    _, Session = start_db()
    with open(os.path.join(os.path.dirname(__file__), "test_data.json")) as f:
        save_to_db(Session(), json.load(f))