Пример #1
0
class Engine(object):
    SOURCES = []

    def __init__(self):
        self.sdb = ShortDBMongo(BASE_URL, host='localhost', db='links')

        self.src_objs = []
        for src_class in Engine.SOURCES:
            src_obj = src_class()
            self.src_objs.append(src_obj)

    def _find_posts(self, surl):
        short_url = surl.get_short_url()
        print 'Scanning for %s...' % (short_url)

        social = surl.get_social()
        posts = social.get('posts', [])
        sinces = social.get('sinces', {})

        for src in self.src_objs:
            name = src.get_name()

            print '\tpolling %s' % (name)
            since = None
            if name in sinces:
                since = sinces[name]

            print '\t\tsince = %s' % (since)
            new_posts = src.find(short_url, since)

            posts.extend(new_posts)
            sinces[name] = src.get_since()

        social['posts'] = posts
        social['sinces'] = sinces

        return social

    def _process_code(self, short_code):
        surl = self.sdb.load(short_code)

        self._find_posts(surl)
        self.sdb.save(surl, update_time=False)

    def run(self, count=-1):
        num_done = 0

        for short_code in self.sdb:
            self._process_code(short_code)

            num_done += 1
            if count > 0 and num_done >= count:
                return
Пример #2
0
    def __init__(self):
        self.sdb = ShortDBMongo(BASE_URL, host='localhost', db='links')

        self.src_objs = []
        for src_class in Engine.SOURCES:
            src_obj = src_class()
            self.src_objs.append(src_obj)
Пример #3
0
import werkzeug

import linkapi
from linklib.db import ShortDB
from linklib.db import ShortDBMongo
from linklib.db import ShortInvalidException
from linklib.url import ShortURL
from linklib.util import UploadedFile
from util import Forwarder
from classify import Classifier


BASE_URL = "http://*****:*****@app.route("/")
def main():
    return ""


@app.route("/<shortcode>", methods=["GET"])
def forward(shortcode):
    return forward_full(shortcode, None)