Esempio n. 1
0
 def rand_nums():
     query = session.query(CarNum).filter_by(registered=False)
     carnum_count = query.count()
     if carnum_count < CarNum.RANDOM_QUAN:
         return query.all()
     seed()
     return sample(query.all(), 10)
Esempio n. 2
0
 def validate_vin(val):
     res = re.match(r"[a-zA-Z]{3}\d{14}", val)
     if res is None:
         raise ValueError('无效的 VIN: \n'
                          '格式错误, 必须为 3位字母 + 14位数字!')
     vin = session.query(VIN).filter_by(val=val).first()
     if vin is not None:
         raise ValueError('无效的 VIN: \n'
                          'VIN已注册!')
     return True
Esempio n. 3
0
async def crawl():
    # log.child()
    #
    # # base = await executor(functools.partial(automap_base), 'thread')
    # # l.d('Executor thread:  automap_base == {} - Base  == {}'.format(automap_base, base))
    # #
    # # await executor(functools.partial(base.prepare, engine, reflect=True), 'thread')
    # # l.d('Executor thread:  base.prepare == {} - engine  == {}'.format(base.prepare, engine))
    # #
    # # crawl_urls = await executor(functools.partial(base.classes.crawl_urls), 'thread')
    # # l.d('Executor thread:  base.classes.crawl_urls == {} - crawl_urls  == {}'
    # #     .format(base.classes.crawl_urls, crawl_urls))
    # direct_queue = asyncio.Queue()
    # page_queue = asyncio.Queue()
    # multi_queue = asyncio.Queue()

    print(session.query(Url))
Esempio n. 4
0
__author__ = 'koller'

from __init__ import session
from tables import Participant, Geocoding
from geopy.geocoders import Nominatim

# set up geolocation service
geolocator = Nominatim(user_agent="ehb")

# unknown cities
known = set([geo.city.lower() for geo in session.query(Geocoding)])
all = set([p.city_with_country().lower() for p in session.query(Participant)])
unknown = all - known

print (unknown)

for city in unknown:
    # print "%s is %s" % (city, chardet.detect(city))
    # c = city.decode("iso-8859-2")  # again, for whatever reason (see generate_map)
    c = city
    loc = geolocator.geocode(c)

    if loc:
        g = Geocoding(c, loc.latitude, loc.longitude)
        session.add(g)
        print ("Added: %s -> %s" % (c, loc.raw))
    else:
        print ("*** not found: %s" % c)

session.commit()
Esempio n. 5
0
__author__ = 'koller'

from __init__ import session
from tables import Participant, Geocoding
from geopy.geocoders import Nominatim

# set up geolocation service
geolocator = Nominatim()

# unknown cities
known = set([geo.city.lower() for geo in session.query(Geocoding)])
all = set([p.city_with_country().lower() for p in session.query(Participant)])
unknown = all - known

print(unknown)

for city in unknown:
    # print "%s is %s" % (city, chardet.detect(city))
    # c = city.decode("iso-8859-2")  # again, for whatever reason (see generate_map)
    c = city
    loc = geolocator.geocode(c)

    if loc:
        g = Geocoding(c, loc.latitude, loc.longitude)
        session.add(g)
        print("Added: %s -> %s" % (c, loc.raw))
    else:
        print("*** not found: %s" % c)

session.commit()
Esempio n. 6
0
from tables import Participant, Geocoding
from random import random
from jinja2 import Environment

# set up Jinja
loader = FileSystemLoader("templates")
env = Environment(loader=loader)
template = env.get_template("osmmap.html")


latlng = list()
names = list()
parts = list()


for p in session.query(Participant):
    loc = session.query(Geocoding).filter(Geocoding.city == p.city_with_country()).first()
    if loc:
        latlng.append("[%f, %f]" % (float(loc.lat) +
                                                          (random() - 0.5) * 0.1, float(loc.long) + (random() - 0.5) * 0.1))
        names.append(p.makeMapLabel())
        parts.append(str(p.final_part))
    else:
        print("Warning: unknown location for %s %s (%d)" %
              (p.firstname, p.lastname, p.id), file=sys.stderr)


ll = u", ".join(latlng)
nn = u", ".join(names)
pp = u", ".join(parts)
Esempio n. 7
0
from __init__ import session
from tables import Participant, Geocoding
from random import random
from jinja2 import Environment

# set up Jinja
loader = FileSystemLoader("templates")
env = Environment(loader=loader)
template = env.get_template("googlemap.html")

latlng = list()
names = list()
parts = list()

for p in session.query(Participant):
    loc = session.query(Geocoding).filter(
        Geocoding.city == p.city_with_country()).first()
    if loc:
        latlng.append("new google.maps.LatLng(%f, %f)" %
                      (float(loc.lat) +
                       (random() - 0.5) * 0.1, float(loc.long) +
                       (random() - 0.5) * 0.1))
        names.append(p.makeMapLabel())
        parts.append(str(p.final_part))
    else:
        print("Warning: unknown location for %s %s (%d)" %
              (p.firstname, p.lastname, p.id),
              file=sys.stderr)

ll = u", ".join(latlng)
Esempio n. 8
0
	def query(cls, **kwargs):
		return session.query(cls, **kwargs)
Esempio n. 9
0
from itunes import *
from blogs import *
from moocs import *
warnings.filterwarnings("ignore")

new_medium_objects = []
new_provider_objects = []
new_content_objects = []
new_category_objects = []
new_formality_objects = []
new_difficulty_objects = []
new_content_category_objects = []

all_medium_titles = {
    medium.name: medium
    for medium in session.query(Medium).all()
}
all_provider_titles = {
    provider.name: provider
    for provider in session.query(Provider).all()
}
all_content_titles = {
    content.content_url: content
    for content in session.query(Content).all()
}
all_category_titles = {
    category.name: category
    for category in session.query(Category).all()
}
all_formality_titles = {
    formality.type: formality