2019-12-11 16:45:44 +00:00
|
|
|
|
import requests
|
|
|
|
|
|
2020-03-03 18:50:22 +00:00
|
|
|
|
from crc.scripts.script import Script
|
2019-12-11 16:45:44 +00:00
|
|
|
|
|
2020-03-03 18:50:22 +00:00
|
|
|
|
|
|
|
|
|
class FactService(Script):
|
|
|
|
|
def get_description(self):
|
2020-06-17 00:42:36 +00:00
|
|
|
|
return """Just your basic class that can pull in data from a few api endpoints and
|
2020-03-03 20:30:42 +00:00
|
|
|
|
do a basic task."""
|
2019-12-11 16:45:44 +00:00
|
|
|
|
|
|
|
|
|
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']
|
|
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
|
def do_task_validate_only(self, task, study_id, workflow_id, **kwargs):
|
|
|
|
|
self.do_task(task, study_id, workflow_id, **kwargs)
|
2020-03-27 12:29:31 +00:00
|
|
|
|
|
2020-05-24 20:13:15 +00:00
|
|
|
|
def do_task(self, task, study_id, workflow_id, **kwargs):
|
2020-02-12 03:13:46 +00:00
|
|
|
|
print(task.data)
|
|
|
|
|
|
|
|
|
|
if "type" not in task.data:
|
2019-12-11 16:45:44 +00:00
|
|
|
|
raise Exception("No Fact Provided.")
|
|
|
|
|
else:
|
2020-02-12 03:13:46 +00:00
|
|
|
|
fact = task.data["type"]
|
2019-12-11 16:45:44 +00:00
|
|
|
|
|
2020-02-12 03:13:46 +00:00
|
|
|
|
if fact == "cat":
|
2020-03-24 18:15:21 +00:00
|
|
|
|
details = "The cat in the hat" # self.get_cat()
|
2019-12-11 16:45:44 +00:00
|
|
|
|
elif fact == "norris":
|
2020-03-24 18:15:21 +00:00
|
|
|
|
details = "Chuck Norris doesn’t read books. He stares them down until he gets the information he wants." # self.get_norris()
|
2019-12-11 16:45:44 +00:00
|
|
|
|
elif fact == "buzzword":
|
2020-03-24 18:15:21 +00:00
|
|
|
|
details = "Move the Needle." # self.get_buzzword()
|
2019-12-11 16:45:44 +00:00
|
|
|
|
else:
|
|
|
|
|
details = "unknown fact type."
|
2020-02-12 03:13:46 +00:00
|
|
|
|
|
2020-07-24 18:33:24 +00:00
|
|
|
|
#self.add_data_to_task(task, details)
|
2020-04-07 18:09:21 +00:00
|
|
|
|
|
2020-02-12 03:13:46 +00:00
|
|
|
|
print(details)
|
|
|
|
|
return details
|