Beispiel #1
0
def update_repos():
    current_time = datetime.now()
    new_time = (current_time.strftime("%c"))

    # Drop tables
    engine = create_engine(ProductionConfig.SQLALCHEMY_DATABASE_URI)
    GitRepo.__table__.drop(engine)
    GitUser.__table__.drop(engine)

    db.create_all()

    # Update users
    users = LocalUser.query.all()
    timezone = {'Time-Zone': 'PST8PDT'}
    for user in users:
        username = user.localuser
        git_data = requests.get(
            f'https://api.github.com/users/{username}/events?per_page=100',
            params=timezone)
        content = git_data.content
        parsed_json = json.loads(content)
        parse_data(parsed_json)

    # Timestamp update
    engine = create_engine(ProductionConfig.SQLALCHEMY_DATABASE_URI)
    Timestamp.__table__.drop(engine)
    db.create_all()

    new_timestamp = Timestamp(time=new_time)

    db.session.add(new_timestamp)
    db.session.commit()
Beispiel #2
0
def set_timestamps(request):
    err = check_arguments(request, ["videoID"])
    if err: return err

    # parse input
    try:
        ts = json.loads(request.POST["timestamps"])
    except ValueError:
        return HttpResponse(status=400, content="invalid timestamps json")

    if not all(
            isinstance(t, dict) and "name" in t and "time" in t for t in ts):
        return HttpResponse(status=400, content="invalid timestamps json")

    # look up video
    vq = get_video_query(request.user, request.POST["videoID"])
    if vq.count() == 0:
        return HttpResponse(status=404,
                            content="videoID %s does not exist for user" %
                            request.POST["videoID"])
    v = vq[0]

    # clear existing timestamps
    oldTimestamps = Timestamp.objects.filter(video=v).delete()

    # attach timestamps to video
    newTimestamps = [
        Timestamp(video=v, name=t["name"], time=t["time"]) for t in ts
    ]
    for t in newTimestamps:
        t.save()

    return HttpResponse(status=200)


#endregion
Beispiel #3
0
async def timestamp():
    vid = await get_video_id()
    loop = asyncio.get_event_loop()
    timestamp = await loop.run_in_executor(None, get_timestamp, vid)
    return Timestamp(current=timestamp)
Beispiel #4
0
def timestamp():
    t = Timestamp(timestamp=datetime.datetime.now())
    db.session.add(t)
    db.session.commit()
    response = [t.timestamp.isoformat() for t in Timestamp.query.all()]
    return '<br>\n'.join(response)
Beispiel #5
0
 def add_video_with_timestamp(self):
     v = self.add_video()
     Timestamp(video=v, name="ts", time=90).save()
Beispiel #6
0
async def timestamp():
    return Timestamp(duration=ytl.vid_time, epoch=ytl.curr_time)