예제 #1
0
def sync(astro_id):
    dao, crawler = None, None

    if astro_id == "quarks":
        dao = AstroDao()
        crawler = QuarksCrawler(app.config.QUARKS_CRAWLER_URL)
    else:
        raise Exception("Invalid astro id %s" % astro_id)

    urls = get_astro_urls(astro_id)
    astro_links = crawler.get_astros(urls)

    last_sync = time.time()
    links_count = len(astro_links) + len(urls)

    dao.add_links(astro_id, astro_links)
    dao.update_astro(astro_id, links_count=links_count, last_sync=last_sync)

    return {"id": astro_id, "links_count": links_count, "last_sync": readable.from_ts(last_sync)}
예제 #2
0
def create_astro(astro_id, initial_data):
    dao = AstroDao()
    astroObj = dao.create_astro(astro_id, initial_data)
    return astroObj
예제 #3
0
def get_astro_urls(astro_id):
    dao = AstroDao()
    urls = dao.get_astro_urls(astro_id)
    return urls
예제 #4
0
def get_astros_ids():
    dao = AstroDao()
    ids = dao.get_astros_ids()
    return ids
예제 #5
0
def get_astro(astro_id):
    dao = AstroDao()
    astro = dao.get_astro_by_id(astro_id)
    return astro