Created
May 28, 2019 12:32
-
-
Save NoFishLikeIan/df0008a9f8f4b09815b20f60ba5b3095 to your computer and use it in GitHub Desktop.
Dad jokes farmer. This is just a stupid joke.
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
import requests | |
import datetime | |
from pymongo import MongoClient | |
def get_dad_joke(): | |
r = requests.get('https://icanhazdadjoke.com/', | |
headers = {'accept': 'text/plain'}) | |
return r.text | |
def generate_post(text): | |
return { | |
"text": text, | |
"tags": ["dad_jokes"] | |
"date": datetime.datetime.utcnow() | |
} | |
if __name__ == '__main__': | |
import time | |
while True: | |
joke = get_dad_joke() | |
post = generate_post(text) | |
client = MongoClient() | |
db = client['dad_jokes'] | |
collection = db[f'{datetime.date.today()}'] | |
post_id = posts.insert_one(post).inserted_id | |
print(f'Dad joke {post_id} ', joke) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment