示例#1
0
def buildObject(search=""):

    venues = db.query("venue/by_geo")

    for item in venues:
        full_geohash = item['key'][1]
        geo_area = full_geohash[:3]
        
        if search == "" or geo_area == search:

            if not geo_area in zones:
                zones[geo_area] = {}
                zones[geo_area].update({
                    "name": getNameFromGeohash(full_geohash),
                    "places": [], 
                    "vehicles": [], 
                    "supplies": [], 
                    "routes": getRoutes(search)
                })

            if item['value']['ct'] and 'trk' in item['value']['ct']:
                zones[geo_area]['vehicles'].append(item['value'])
            else:
                zones[geo_area]['places'].append(item['value'])


            time.sleep(0.3)
            items = getSuppliesForVenue(item['value']['_id'])
            if items:
                for item in items:
                    zones[geo_area]['supplies'].append(item['value'])

    return zones
示例#2
0
def threads():
    for thread in db.query(Thread).all():
        for msg in thread.messages:
            if msg.sender == SETTINGS.okcupid['username']:
                print '[OkBot]:  %s' % msg.body.encode('utf-8').strip()
            else:
                print '[Suitor]: %s' % msg.body.encode('utf-8').strip()
        print
示例#3
0
文件: console.py 项目: rmcgibbo/okbot
def threads():
    for thread in db.query(Thread).all():
        for msg in thread.messages:
            if msg.sender == SETTINGS.okcupid["username"]:
                print "[OkBot]:  %s" % msg.body.encode("utf-8").strip()
            else:
                print "[Suitor]: %s" % msg.body.encode("utf-8").strip()
        print
示例#4
0
    def get_participants(self):
        rows = db.query('SELECT user_id FROM lunch_participants '
                     'WHERE lunch_id=%s', int(self.id))
        if not rows:
            return None

        participants = []
        for row in rows:
            participants.append(User.get(row['user_id']))

        return participants
示例#5
0
def getRoutes(geo_area):
    matching_routes = []
    routes = db.query("route/by_geo")
    for item in routes:
        did_match = False
        if item['value']['gp']:
            for point in item['value']['gp']:
                if point[:3] == geo_area:
                    did_match = True
        if did_match:
            matching_routes.append(item['value'])
    return matching_routes
示例#6
0
    def get_all(cls, lunch_id):
        rows = db.query('SELECT id, lunch_id, tag FROM lunch_tags '
                        'WHERE lunch_id = %s',
                        int(lunch_id))
        if not rows:
            return None

        tags = []
        for row in rows:
            tags.append(cls(**row))

        return tags
示例#7
0
文件: app.py 项目: rmcgibbo/okbot
def respond_to_messages(cupidbot, twitterstream):
    """Respond to all of the unreplied messages on the cupidbot with an
    entry from the twitterstream

    Parameters
    ----------
    cupidbot : okcupid.OkCupid
        An instance of the okcupid webdriver API, capable of interacting
        programmatically with the site
    twitterstream : twitter.Tweeterator
        An iterator that provides the text of tweets as a stream. Also needs
        to have a `pull` method asking it to load up some more tweets into
        its buffer
    """

    threads = cupidbot.get_threads(["unreadMessage", "readMessage"])
    logging.info("Replying to %s", threads)

    logging.info("number of unreplied messages: %d", len(threads))
    twitterstream.pull(len(threads))
    for tid in threads:
        log_threads(cupidbot, [tid])
        thread = db.query(models.Thread).filter_by(okc_id=tid).first()
        target = thread.messages[-1].body

        get_tweet = True

        while get_tweet:
            response = twitterstream.next(target=target)
            try:
                print 'RESPONDING WITH: "%s"' % response
            except UnicodeEncodeError:
                print "Unicode error. Getting new tweet"
                continue

            sys.stdout.flush()

            rlist, _, _ = select([sys.stdin], [], [], PROMPT_TIMEOUT)
            if len(rlist) == 0:
                get_tweet = False
            else:
                # the user entered something, get a new tweet
                get_tweet = True

        cupidbot.reply_to_thread(tid, response, dry_run=False)
        # log_threads(cupidbot, [tid])
        okcupid.sleep()
示例#8
0
文件: app.py 项目: stavsmart/okbot
def respond_to_messages(cupidbot, twitterstream):
    """Respond to all of the unreplied messages on the cupidbot with an
    entry from the twitterstream

    Parameters
    ----------
    cupidbot : okcupid.OkCupid
        An instance of the okcupid webdriver API, capable of interacting
        programmatically with the site
    twitterstream : twitter.Tweeterator
        An iterator that provides the text of tweets as a stream. Also needs
        to have a `pull` method asking it to load up some more tweets into
        its buffer
    """

    threads = cupidbot.get_threads(['unreadMessage', 'readMessage'])
    logging.info('Replying to %s', threads)

    logging.info('number of unreplied messages: %d', len(threads))
    twitterstream.pull(len(threads))
    for tid in threads:
        log_threads(cupidbot, [tid])
        thread = db.query(models.Thread).filter_by(okc_id=tid).first()
        target = thread.messages[-1].body

        get_tweet = True

        while get_tweet:
            response = twitterstream.next(target=target)
            try:
                print 'RESPONDING WITH: "%s"' % response
            except UnicodeEncodeError:
                print 'Unicode error. Getting new tweet'
                continue

            sys.stdout.flush()

            rlist, _, _ = select([sys.stdin], [], [], PROMPT_TIMEOUT)
            if len(rlist) == 0:
                get_tweet = False
            else:
                # the user entered something, get a new tweet
                get_tweet = True

        cupidbot.reply_to_thread(tid, response, dry_run=False)
        #log_threads(cupidbot, [tid])
        okcupid.sleep()
示例#9
0
    def get_page(cls, page=0):
        PER_PAGE = 20

        offset = int(page) * PER_PAGE
        limit = offset + PER_PAGE
        rows = db.query('SELECT id, food, place, lunch_date, creator_id, '
                        'slots '
                        'FROM lunch ORDER BY lunch_date DESC LIMIT %s,%s', offset, limit)
        if not rows:
            return None

        instances = []
        for row in rows:
            instance = cls(**row)
            instance.tags = LunchTag.get_all(instance.id)
            instances.append(instance)
        return instances
示例#10
0
def getSuppliesForVenue(venue_id):
    return db.query("venue/by_item", reduce=False, startkey=[ venue_id ], endkey=[ venue_id, {}, {}])