Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created March 6, 2018 03:13
Show Gist options
  • Save laixintao/cb03f0b01bfd30f93337a6497f27ee45 to your computer and use it in GitHub Desktop.
Save laixintao/cb03f0b01bfd30f93337a6497f27ee45 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import signal
import sys
import asyncio
import aiohttp
import json
loop = asyncio.get_event_loop()
client = aiohttp.ClientSession(loop=loop)
async def get_json(client, url):
async with client.get(url) as response:
assert response.status == 200
return await response.read()
async def get_reddit_top(subreddit, client):
print("start get json from {}".format(subreddit))
data1 = await get_json(client, 'https://www.reddit.com/r/' + subreddit + '/top.json?sort=top&t=day&limit=5')
print("{} arrived".format(subreddit))
j = json.loads(data1.decode('utf-8'))
for i in j['data']['children']:
score = i['data']['score']
title = i['data']['title']
link = i['data']['url']
print(str(score) + ': ' + title + ' (' + link + ')')
print('DONE:', subreddit + '\n')
def signal_handler(signal, frame):
loop.stop()
client.close()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
for topic in ("python", "programming", "compsci"):
print("Start ensure future: {}".format(topic))
asyncio.ensure_future(get_reddit_top(topic, client))
loop.run_forever()
@laixintao
Copy link
Author

Start ensure future: python
Start ensure future: programming
Start ensure future: compsci
start get json from python
start get json from programming
start get json from compsci
programming arrived
1472: John Carmack - Programming Neural Networks on OpenBSD (https://www.facebook.com/permalink.php?story_fbid=2110408722526967&id=100006735798590)
272: Xray - Atom team is experimenting with next gen Rust / Electron based text editor (https://github.com/atom/xray)
63: Clang is now used to build Chrome for Windows (http://blog.llvm.org/2018/03/clang-is-now-used-to-build-chrome-for.html)
41: Java 10: Changing variables as you know them by introducing Local Variable Type Inference (http://www.deadcoderising.com/java-10-changing-variables-as-you-know-them-by-introducing-local-variable-type-inference/)
34: AI learns to play PACMAN || Part 1 the making of Pacman (https://www.youtube.com/watch?v=qwhXIzNrb9w)
DONE: programming

compsci arrived
29: Language semantics (https://www.reddit.com/r/compsci/comments/824c3n/language_semantics/)
6: What are some famous language/software bugs? (https://www.reddit.com/r/compsci/comments/8285gc/what_are_some_famous_languagesoftware_bugs/)
2: Advice Needed on Programming Planning Process (https://www.reddit.com/r/compsci/comments/82asw3/advice_needed_on_programming_planning_process/)
3: Is the cutset of a network flow's min-cut the set of bottleneck edges? (https://www.reddit.com/r/compsci/comments/823lou/is_the_cutset_of_a_network_flows_mincut_the_set/)
2: Implementing a time-aware hashmap (https://interviewcache.com/blog/time-aware-hashmap/)
DONE: compsci

python arrived
559: I wrote a script which goes through my LastPass vault and checks all passwords against haveibeenpwned.com and I hope somebody else finds it useful (https://github.com/dionysio/haveibeenpwned_lastpass)
22: PyCon Namibia 2018 - conference report (https://na.pycon.org/en/2018/)
12: Implementation of Convolutional Neural Network using Python and Keras (https://rubikscode.net/2018/03/05/implementation-of-convolutional-neural-network-using-python-and-keras/)
7: Jupyter Lab Release! (http://www.zdnet.com/article/can-data-science-notebooks-get-real-jupyter-lab-releases-to-users/)
7: Simple home surveillance application using google object detection api (https://www.reddit.com/r/Python/comments/824skg/simple_home_surveillance_application_using_google/)
DONE: python

^Cuse_ensure_future.py:33: RuntimeWarning: coroutine 'ClientSession.close' was never awaited
  client.close()
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x108a5f2e8>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment