def set_country():
    session = Session()
    for follower in session.query(Follower).order_by(Follower.user_id):
        if hasattr(follower, 'latitude') and hasattr(
                follower, 'longitude') and follower.country is None:
            country = locate_country(follower.latitude, follower.longitude)
            if country:
                follower.country = country
                session.commit()
def with_country():
    session = Session()
    for follower in session.query(Follower).filter(
            Follower.country != None).all():
        print follower.country
    count = session.query(Follower.country, func.count(
        Follower.country)).group_by(Follower.country).all()
    for el in count:
        print el[0], el[1]
def load_geos_test():
    session = Session()
    for follower in session.query(Follower).order_by(Follower.user_id):
        follower.geotag = get_geos(follower.user_id)
    session.commit()
def test_func():
    session = Session()
    for follower in session.query(Follower).all():
        print follower
def followers_from_db():
    session = Session()
    return session.query(Follower).order_by(Follower.user_id)
コード例 #6
0
from sqlalchemy.orm import mapper

from lib import get_followers
from lib import get_geos
from follower import Follower

from instadb import geo_table
from instadb import Session

session = Session()

followed_by = get_followers('1921850126')

# mapper(Follower, geo_table)
# fill db with followers, step 1
for follower in followed_by:
    print follower.id
    session.add(Follower(user_id=follower.id))
session.commit()

#TODO fill DB with GEOS
# get_geos_for_followers(followed_by)

for follower in session.query(Follower).order_by(Follower.user_id):
    location = get_geos(follower.user_id)
    # if hasattr(location, 'id'):
    #     follower.location_id = location.id
    if hasattr(location, 'point'):
        if (location.point != None):
            follower.latitude = location.point.latitude
            follower.longitude = location.point.longitude