コード例 #1
0
ファイル: instagram.py プロジェクト: digideskio/okavango
def main(): ## called via instagram_grabber.py
    try:
        response = requests.get("https://api.instagram.com/v1/tags/%s/media/recent?client_id=%s" % (settings['hashtag'], settings['client_id']))
        photos = response.json()['data']
    except Exception as e:
        log.error(log.exc(e))
    for photo in photos:
        image_id = None
        try:
            username = photo['user']['username']
            if username not in ACCOUNTS:
                log.info("Skipping photo by %s" % username)
                continue
            data = {}
            data['Url'] = photo['link']
            dup = db.features.find_one({'properties.FeatureType': 'instagram', 'properties.Url': data['Url']})
            if dup is not None:
                log.info("--> skipping duplicate")
                continue
            data['Member'] = MEMBERS[ACCOUNTS.index(username)]
            data['Caption'] = photo['caption']['text']               
            data['Tags'] = photo['tags']
            data['Filter'] = photo['filter']
            data['t_utc'] = int(photo['created_time'])
            data['InstagramPhotoURL'] = photo['images']['standard_resolution']['url']
            try:
                path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "uploads", "%s_%s.jpg" % (util.timestamp(), data['Url'].split("/")[-2])))
                net.grab(data['InstagramPhotoURL'], path)
                image_data = process_image(path, data['Member'], data['t_utc'])
                if image_data is None:
                    log.info("--> no image data")
                else:
                    success, image_id = ingest_data("image", image_data.copy())   # make a second request for the image featuretype
                    if not success:
                        log.error(image_id)
                    image_data['ImageUrl'] = image_data['Url']
                    del image_data['Url']
                    data.update(image_data)
            except Exception as e:
                log.error(log.exc(e))
        except Exception as e:
            log.error(log.exc(e))
            return
        success, post_id = ingest_data("instagram", data)
        if not success:
            log.error("--> failed: %s" % post_id)
        else:
            log.info("--> %s" % post_id)
        try:
            db.features.update({'_id': image_id}, {'$set': {'properties.InstagramID': post_id}})
        except Exception as e:
            log.error(log.exc(e))
コード例 #2
0
ファイル: geograph.py プロジェクト: brianhouse/quotidio
def get_map(city, bounds):

    CLOUDMADE_KEY = "9e44428bdd434d7697b10be5f975b849"
    STYLE_ID = 63595
    ZOOM = 12

    params = {  #'center': "%s,%s" % (city.centroid.lat, city.centroid.lon),
                #'zoom': ZOOM,    
                'bbox': "%s,%s,%s,%s" % (bounds[0].lat, bounds[0].lon, bounds[1].lat, bounds[1].lon),
                'size': "%sx%s" % (SIZE[0], SIZE[1]),
                'format': "png",
                'styleid': STYLE_ID,
                'marker': "size:big|url:%s|opacity:1.0|%s,%s|%s,%s" % ("http://brianhouse.net/download/quotidio_marker.png", bounds[0].lat, bounds[0].lon, bounds[1].lat, bounds[1].lon),
                }
    urlstring = "http://staticmaps.cloudmade.com/%s/staticmap" % CLOUDMADE_KEY
        
    print
    urlstring = "%s?%s" % (urlstring, net.urlencode(params))
    print urlstring
    
    try:    
        net.grab(urlstring, "screenshots/%s_geograph_%s,%s_map.png" % (int(time.time()), city.centroid.lat, city.centroid.lon))
    except Exception as e:
        log.error(log.exc(e))
コード例 #3
0
ファイル: maps.py プロジェクト: brianhouse/quotidio
STYLE_ID = 63595
WIDTH = 640
HEIGHT = 480
ZOOM = 12

cities = [  (39.7119386606,-104.950620722),
            (40.7241002316,-73.9162034413),
            (41.7252473831,-74.0063800812),
            (44.9335235581,-93.219538549),
            (38.9482655525,-77.0590810776)
            ]


for city in cities:
        
    params = {  'center': "%s,%s" % (city[0], city[1]),
                'zoom': ZOOM,    
                'size': "%sx%s" % (WIDTH, HEIGHT),
                'format': "png",
                'styleid': STYLE_ID
                # 'marker': "size:big|url:%s|opacity:1.0|%s, %s" % ("http://brianhouse.net/download/marker.png", city[0], city[1]),
                }
    urlstring = "http://staticmaps.cloudmade.com/%s/staticmap" % CLOUDMADE_KEY
        
    urlstring = "%s?%s" % (urlstring, net.urlencode(params))
    print urlstring
        
    net.grab(urlstring, "screenshots/maps/map_%s,%s.png" % (city[0], city[1]))
    print "%s,%s" % (city[0], city[1])

コード例 #4
0
ファイル: pull.py プロジェクト: brianhouse/citibikesound
TODO: make bucket


"""

import time, os
from housepy import config, log, net, s3

ENDPOINT = "http://appservices.citibikenyc.com/data2/stations.php"

filename = "%s.txt" % str(time.time()).split('.')[0]

log.info("----- grab attempt")

try:
    net.grab(ENDPOINT, filename)
except Exception as e:
    log.error(log.exc(e))
    exit()

log.info("got %s, pushing..." % filename)    

try:
    s3.upload(filename)
except Exception as e:
    log.error(log.exc(e))
    exit()

log.info("upload complete")

os.remove(filename)