Created
February 5, 2019 23:57
-
-
Save NeuronQ/c9182b2e7e6b9a27908d4f181f7dcc03 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
# async_scrape.py (requires Python 3.7+) | |
import asyncio, random, time | |
async def fetch_url(url): | |
print(f"~ executing fetch_url({url})") | |
t = time.perf_counter() | |
await asyncio.sleep(random.randint(1, 5)) | |
print(f"time of fetch_url({url}): {time.perf_counter() - t:.2f}s") | |
return f"<em>fake</em> page html for {url}" | |
async def analyze_sentiment(html): | |
print(f"~ executing analyze_sentiment('{html}')") | |
t = time.perf_counter() | |
await asyncio.sleep(random.randint(1, 5)) | |
r = {"positive": random.uniform(0, 1)} | |
print(f"time of analyze_sentiment('{html}'): {time.perf_counter() - t:.2f}s") | |
return r | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment