class WebsiteInteraction:
    def __init__(self):
        self.id = 0
        self.encryption = Encryption()

    def post_request_to_sports_canary(self, event_name, score_1, score_2, score_applicable, stattleship_slug,
                                      sport_type, team_1_percentage_win, team_2_percentage_win, team_1_name, team_2_name):

        try:
            enc = self.encryption.encrypt_node('API-Passkey')
            data = {'event_name': event_name, 'score_1': score_1,
                    'score_2': score_2, 'stattleship_slug': stattleship_slug, 'event_date': datetime.datetime.now(),
                    'score_applicable': score_applicable, 'sport_type': sport_type,
                    'team_1_percentage_win': team_1_percentage_win, 'team_2_percentage_win': team_2_percentage_win,
                    'team_1_name': team_1_name, 'team_2_name': team_2_name,
                    'encrypted': str(enc),
                    }

            r = requests.post('http://sportscanary.com/api/results', data=data)
            json_response = r.text
            json_response = json.loads(json_response)
            self.id = json_response['_id']
            return r.status_code

        except:
            print('Error posting to game.')
            return False

    def delete_request_to_sports_canary(self):
        r = requests.delete('http://sportscanary.com/api/results/' + str(self.id) + '/edit')
        return r.status_code
Exemplo n.º 2
0
class WebsiteInteraction:
    def __init__(self):
        self.id = 0
        self.encryption = Encryption()

    def post_request_to_sports_canary(self, event_name, score_1, score_2, score_applicable):
        enc = self.encryption.encrypt_node('API-Passkey')
        data = {'event_name': event_name, 'score_1': score_1,
                'score_2': score_2, 'event_date': datetime.datetime.now(),
                'score_applicable': score_applicable, 'encrypted': str(enc)}
        r = requests.post('http://sportscanary.com/api/results', data=data)
        json_response = r.text
        json_response = json.loads(json_response)
        self.id = json_response['_id']
        return r.status_code

    def delete_request_to_sports_canary(self):
        r = requests.delete('http://sportscanary.com/api/results/' + str(self.id) + '/edit')
        return r.status_code
 def test_decrypt_node(self):
     encryption = Encryption()
     enc = encryption.encrypt_node('API-Passkey')
     decrypted_enc = encryption.decrypt_node(enc)
     self.assertEqual('API-Passkey', decrypted_enc)
 def test_encrypt_node_length(self):
     encryption = Encryption()
     enc = encryption.encrypt_node('API-Passkey')
     self.assertEqual(32, len(enc))