Created
September 16, 2018 18:45
-
-
Save Jan-Zeiseweis/e2cbf29afa4c452650709fed072aa1cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
from pathlib import Path | |
from flask import Flask, request | |
app = Flask(__name__) | |
seen_video_ids_path = Path("video_ids.pkl") | |
if seen_video_ids_path.is_file(): | |
with open(str(seen_video_ids_path), 'rb') as dump: | |
seen_videos = pickle.load(dump) | |
else: | |
seen_videos = [] | |
print(len(seen_videos)) | |
@app.route('/view/<video_id>') | |
def view(video_id): | |
global seen_videos | |
if not viewed(video_id): | |
seen_videos.append(video_id) | |
with open(str(seen_video_ids_path), 'bw') as dump: | |
pickle.dump(seen_videos, dump) | |
return "200" | |
def viewed(video_id): | |
global seen_videos | |
return video_id in seen_videos | |
@app.route('/chk/<video_id>') | |
def chk(video_id): | |
msg = "not viewed" | |
if viewed(video_id): | |
print(video_id) | |
msg = "viewed" | |
return msg | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment