def test_format_unix_time(self): unix1 = 0 assert Commons.format_unix_time(unix1) == "1970-01-01 00:00:00" unix2 = 1000000000 assert Commons.format_unix_time(unix2) == "2001-09-09 01:46:40" unix3 = 1234567890 assert Commons.format_unix_time(unix3) == "2009-02-13 23:31:30"
def run(self, line, user_obj, destination_obj=None): input_clean = line.strip().lower() url = "http://api.randomuser.me/0.6/?nat=gb&format=json" # Get api response json_dict = Commons.load_url_json(url) user_dict = json_dict['results'][0]['user'] # Construct response name = (user_dict['name']['title'] + " " + user_dict['name']['first'] + " " + user_dict['name']['last']).title() email = user_dict['email'] address = user_dict['location']['street'].title() + ", " address += user_dict['location']['city'].title() + ", " address += user_dict['location']['postcode'] username = user_dict['username'] password = user_dict['password'] date_of_birth = Commons.format_unix_time(int(user_dict['dob'])) phone_home = user_dict['phone'] phone_mob = user_dict['cell'] national_insurance = user_dict['NINO'] pronoun = "he" if user_dict['gender'] == "male" else "she" pronoun_possessive = "his" if user_dict['gender'] == "male" else "her" if input_clean not in ["more", "full", "verbose", "all"]: output = "I have generated this person: Say hello to " + name + ". " output += pronoun.title() + " was born at " + date_of_birth + "." return output output = "I have generated this person: Say hello to " + name + ". " output += pronoun.title() + " was born at " + date_of_birth + " and lives at " + address + ". " output += pronoun.title() + " uses the email " + email + ", the username \"" + username + \ "\" and usually uses the password \"" + password + "\". " output += pronoun_possessive.title() + " home number is " + phone_home + " but " output += pronoun_possessive + " mobile number is " + phone_mob + ". " output += pronoun_possessive + " national insurance number is " + national_insurance + "." return output
def run(self, event): input_clean = event.command_args.strip().lower() url = "https://api.randomuser.me/0.6/?nat=gb&format=json" # Get api response json_dict = Commons.load_url_json(url) user_dict = json_dict['results'][0]['user'] # Construct response name = "{} {} {}".format(user_dict['name']['title'], user_dict['name']['first'], user_dict['name']['last']).title() email = user_dict['email'] address = "{}, {}, {}".format(user_dict['location']['street'].title(), user_dict['location']['city'].title(), user_dict['location']['postcode']) username = user_dict['username'] password = user_dict['password'] date_of_birth = Commons.format_unix_time(int(user_dict['dob'])) phone_home = user_dict['phone'] phone_mob = user_dict['cell'] national_insurance = user_dict['NINO'] pronoun = "he" if user_dict['gender'] == "male" else "she" pronoun_possessive = "his" if user_dict['gender'] == "male" else "her" if input_clean not in ["more", "full", "verbose", "all"]: output = "I have generated this person: Say hello to {}. {} was born at {}.".format(name, pronoun.title(), date_of_birth) return event.create_response(output) output = "I have generated this person: Say hello to {}. " \ "{} was born at {} and lives at {}. " \ "{} uses the email {}, the username {} and usually uses the password \"{}\". " \ "{} home number is {} but {} mobile number is {}. " \ "{} national insurance number is {}.".format(name, pronoun.title(), date_of_birth, address, pronoun.title(), email, username, password, pronoun_possessive.title(), phone_home, pronoun_possessive, phone_mob, pronoun_possessive.title(), national_insurance) return event.create_response(output)