Skip to content

Instantly share code, notes, and snippets.

@Jan-Zeiseweis
Created September 16, 2018 18:45
Show Gist options
  • Save Jan-Zeiseweis/e2cbf29afa4c452650709fed072aa1cf to your computer and use it in GitHub Desktop.
Save Jan-Zeiseweis/e2cbf29afa4c452650709fed072aa1cf to your computer and use it in GitHub Desktop.
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