Last active 1624560119

Gets random comment from /r/gonewild, since they're pretty much all compliments. http://compliment.b303.me Warning: May contain sexual content

Steven Smith revised this gist 1448689209. Go to revision

1 file changed, 1 insertion, 1 deletion

fun-uses.md renamed to uses.md

@@ -11,7 +11,7 @@ Text to speech (Linux)
11 11
12 12 Text to speech (Windows) (untested)
13 13 -----------------------------------
14 - Uses [ptts](http://jampal.sourceforge.net/ptts.html) and [wget](http://nebm.ist.utl.pt/~glopes/wget/)
14 + Uses [ptts](http://jampal.sourceforge.net/ptts.html) and [curl](http://curl.haxx.se/download.html)
15 15
16 16 :top
17 17 curl http://compliment.b303.me -O compliment.txt

Steven Smith revised this gist 1448689108. Go to revision

1 file changed, 21 insertions

fun-uses.md(file created)

@@ -0,0 +1,21 @@
1 + Uses
2 + ====
3 +
4 + Text to speech (OSX)
5 + --------------------
6 + while true; do msg=$(curl -sk http://compliment.b303.me); echo "$msg"; say "$msg" -v "Samantha"; done
7 +
8 + Text to speech (Linux)
9 + ----------------------
10 + while true; do msg=$(curl -sk http://compliment.b303.me); echo "$msg" | espeak; echo "$msg"; done
11 +
12 + Text to speech (Windows) (untested)
13 + -----------------------------------
14 + Uses [ptts](http://jampal.sourceforge.net/ptts.html) and [wget](http://nebm.ist.utl.pt/~glopes/wget/)
15 +
16 + :top
17 + curl http://compliment.b303.me -O compliment.txt
18 + SET /p MSG=<compliment.txt
19 + echo %MSG%
20 + echo %MSG% | ptts
21 + goto top

Steven Smith revised this gist 1448687946. Go to revision

1 file changed, 3 insertions, 3 deletions

compliment.b303.me.py

@@ -34,10 +34,10 @@ def all():
34 34 return jsonify({"comments": comments})
35 35 return "<ul>\n" + "\n".join("<li>{}</li>\n".format(c) for c in comments) + "</ul>"
36 36
37 + update_comments()
38 + scheduler.add_job(update_comments, 'interval', minutes=15)
39 + scheduler.start()
37 40 if __name__ == "__main__":
38 - update_comments()
39 - scheduler.add_job(update_comments, 'interval', minutes=15)
40 - scheduler.start()
41 41 try:
42 42 app.run(port=56735, debug=True)
43 43 finally:

Steven Smith revised this gist 1448647935. Go to revision

1 file changed, 3 insertions, 3 deletions

compliment.b303.me.py

@@ -34,10 +34,10 @@ def all():
34 34 return jsonify({"comments": comments})
35 35 return "<ul>\n" + "\n".join("<li>{}</li>\n".format(c) for c in comments) + "</ul>"
36 36
37 - update_comments()
38 - scheduler.add_job(update_comments, 'interval', minutes=15)
39 - scheduler.start()
40 37 if __name__ == "__main__":
38 + update_comments()
39 + scheduler.add_job(update_comments, 'interval', minutes=15)
40 + scheduler.start()
41 41 try:
42 42 app.run(port=56735, debug=True)
43 43 finally:

Steven Smith revised this gist 1448641666. Go to revision

1 file changed, 6 insertions

compliment.b303.me.py

@@ -28,6 +28,12 @@ def compliment():
28 28 return jsonify({"compliment": random.choice(comments)})
29 29 return random.choice(comments)
30 30
31 + @app.route("/comments")
32 + def all():
33 + if request_wants_json():
34 + return jsonify({"comments": comments})
35 + return "<ul>\n" + "\n".join("<li>{}</li>\n".format(c) for c in comments) + "</ul>"
36 +
31 37 update_comments()
32 38 scheduler.add_job(update_comments, 'interval', minutes=15)
33 39 scheduler.start()

Steven Smith revised this gist 1448641053. Go to revision

No changes

Steven Smith revised this gist 1448641033. Go to revision

1 file changed, 38 insertions

compliment.b303.me.py(file created)

@@ -0,0 +1,38 @@
1 + #!/usr/bin/env python3
2 + import requests
3 + from flask import *
4 + import random
5 +
6 + from apscheduler.schedulers.background import BackgroundScheduler
7 +
8 + app = Flask(__name__)
9 + scheduler = BackgroundScheduler()
10 + url = "https://reddit.com/r/gonewild/comments.json?limit=200"
11 + comments = []
12 +
13 + def request_wants_json():
14 + best = request.accept_mimetypes \
15 + .best_match(['application/json', 'text/html'])
16 + return best == 'application/json' and \
17 + request.accept_mimetypes[best] > \
18 + request.accept_mimetypes['text/html']
19 +
20 + def update_comments():
21 + global comments
22 + data = requests.get(url, headers={"User-Agent": "/u/suudo http://compliment.b303.me (comments from gonewild)"}).json()
23 + comments = [a["data"]["body"] for a in data["data"]["children"]]
24 +
25 + @app.route("/")
26 + def compliment():
27 + if request_wants_json():
28 + return jsonify({"compliment": random.choice(comments)})
29 + return random.choice(comments)
30 +
31 + update_comments()
32 + scheduler.add_job(update_comments, 'interval', minutes=15)
33 + scheduler.start()
34 + if __name__ == "__main__":
35 + try:
36 + app.run(port=56735, debug=True)
37 + finally:
38 + scheduler.shutdown()
Newer Older