Esempio n. 1
0
File: tests.py Progetto: slok/dwarf
    def test_detect_country_location_with_geoip(self):
        ip = "72.14.207.99"
        correct_res = {'country_code': 'US', 'country_name': 'United States'}

        result = detect_country_location_with_geoip(ip)

        self.assertEqual(correct_res, result)
Esempio n. 2
0
File: tasks.py Progetto: slok/dwarf
def click_link(token, request_meta_dict):

    #Extract data
    user_agent = request_meta_dict.get('HTTP_USER_AGENT')
    data = detect_browser_and_OS(user_agent)
    ip = request_meta_dict.get('REMOTE_ADDR')
    language = request_meta_dict.get('HTTP_ACCEPT_LANGUAGE',
                                     "None").split(",")[0]
    location = detect_country_location_with_geoip(ip).get('country_code')

    #TODO: remote host

    c = Click(token=token, browser=data[1], os=data[2], ip=ip,
              language=language, location=location)

    # Metrics
    ClickMetrics().increment()
    TotalClickMetrics().increment()
    c.save()