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 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 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)
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 followers_from_db():
    session = Session()
    return session.query(Follower).order_by(Follower.user_id)
def test_func():
    session = Session()
    for follower in session.query(Follower).all():
        print follower
from instadb import Session
from lib import get_geos
import sys
from random import randint


apis = [
    InstagramAPI(client_id="bc3f22e5807c4e5aa9e1c9e5bf391f77", client_secret="4f88a95213ae4e57a70f318b7f6ac81c"),
    InstagramAPI(client_id="ade077a508f241b599aa55d924730a10", client_secret="85a2c94c85d844b79d39e86e7d8d84a7"),
]

api = apis[randint(0, len(apis) - 1)]

print api

session = Session()


def parse_follower(follower_info):
    flw = session.query(Follower).filter(Follower.user_id == follower_info.id, Follower.owner == sys.argv[-1]).first()
    if flw is None:
        location = get_geos(follower_info.id)
        if hasattr(location, "point"):
            if location.point != None:
                # follower_info.country = location.point.latitude
                follower_info.latitude = location.point.latitude
                follower_info.longitude = location.point.longitude
                # follower_info.country = locate_country(follower_info.latitude, follower_info.longitude)
                # follower_info.country = locate_country(location.point.latitude, location.point.longitude)
                return follower_info
    return False
Exemplo n.º 12
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
Exemplo n.º 13
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
from follower import Follower
from instadb import Session
from getdatadb import locate_country, locate_country_code

session = Session()

counter = 0


def fill_countries():
    for follower in session.query(Follower).all():
        if follower.country is None:
            follower.country = locate_country(follower.latitude,
                                              follower.longitude)
            follower.code = locate_country_code(follower.latitude,
                                                follower.longitude)
            session.commit()
            fill_countries()


fill_countries()
import multiprocessing as mps
from instagram.client import InstagramAPI
from lib import api
from follower import Follower
from instadb import Session
from lib import get_geos
import sys
from random import randint


apis = [InstagramAPI(client_id='bc3f22e5807c4e5aa9e1c9e5bf391f77', client_secret='4f88a95213ae4e57a70f318b7f6ac81c'),
       InstagramAPI(client_id='ade077a508f241b599aa55d924730a10', client_secret='85a2c94c85d844b79d39e86e7d8d84a7')]

api = apis[randint(0, len(apis) - 1)]

session = Session()

def parse_follower(follower_info):
    flw = session.query(Follower).filter(Follower.user_id==follower_info.id, Follower.owner == sys.argv[-1]).first()
    if flw is None:
        location = get_geos(follower_info.id)
        user = api.user(user_id=follower_info.id)
        if 'counts' in user:
            follower_info.followers_count = user.counts['followed_by']
        if hasattr(location, 'point'):
            if(location.point != None):
                # follower_info.country = location.point.latitude
                follower_info.latitude = location.point.latitude
                follower_info.longitude = location.point.longitude
                # follower_info.country = locate_country(follower_info.latitude, follower_info.longitude)
                # follower_info.country = locate_country(location.point.latitude, location.point.longitude)