This repository has been archived on 2018-10-14. You can view files and clone it, but cannot push or open issues or pull requests.
twtxt-registry/app.py

25 lines
479 B
Python
Raw Normal View History

2018-10-14 03:51:10 +00:00
from flask import *
app = Flask(__name__)
2018-10-14 18:51:54 +00:00
def pagination(tweets,page):
if page==1:
2018-10-14 21:01:48 +00:00
return tweets[-20:]
2018-10-14 18:51:54 +00:00
else:
2018-10-14 21:01:48 +00:00
return tweets[(page*-20):((page-1)*-20)]
2018-10-14 18:51:54 +00:00
2018-10-14 04:32:59 +00:00
TWEETFILE = "tweets.txt"
USERFILE = "users.txt"
def get_tweets():
with open(TWEETFILE) as f:
2018-10-14 18:51:54 +00:00
return f.read().rstrip().split("\n")
2018-10-14 03:57:12 +00:00
2018-10-14 03:51:10 +00:00
@app.route("/")
def index():
return "wewlad"
2018-10-14 03:57:12 +00:00
@app.route("/api/plain/tweets")
2018-10-14 04:03:07 +00:00
def tweets_get():
2018-10-14 21:01:48 +00:00
page = int(request.args.get("page",1))
return "\n".join(pagination(get_tweets(),page))