Skip to content

Instantly share code, notes, and snippets.

@NoFishLikeIan
Created May 28, 2019 12:32
Show Gist options
  • Save NoFishLikeIan/df0008a9f8f4b09815b20f60ba5b3095 to your computer and use it in GitHub Desktop.
Save NoFishLikeIan/df0008a9f8f4b09815b20f60ba5b3095 to your computer and use it in GitHub Desktop.
Dad jokes farmer. This is just a stupid joke.
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