mirror of
https://github.com/sartography/cr-connect-workflow.git
synced 2025-02-23 05:08:32 +00:00
And dropping the API call in the Fact Service so we aren't hitting external apis for the time being.
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import requests
|
|
|
|
|
|
class FactService:
|
|
"""Just your basic class that can pull in data from a few api endpoints and do a basic task."""
|
|
|
|
def get_cat(self):
|
|
response = requests.get('https://cat-fact.herokuapp.com/facts/random')
|
|
return response.json()['text']
|
|
|
|
def get_buzzword(self):
|
|
response = requests.get('https://corporatebs-generator.sameerkumar.website/')
|
|
return response.json()['phrase']
|
|
|
|
def get_norris(self):
|
|
response = requests.get('https://api.chucknorris.io/jokes/random')
|
|
return response.json()['value']
|
|
|
|
def do_task(self, data, **kwargs):
|
|
if "Fact.type" not in data:
|
|
raise Exception("No Fact Provided.")
|
|
else:
|
|
fact = data["Fact.type"]
|
|
|
|
if True:
|
|
details = "Assertively Incubate Seamless Niches"
|
|
elif fact == "cat":
|
|
details = self.get_cat()
|
|
elif fact == "norris":
|
|
details = self.get_norris()
|
|
elif fact == "buzzword":
|
|
details = self.get_buzzword()
|
|
else:
|
|
details = "unknown fact type."
|
|
data['details'] = details
|