diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-04-10 13:26:06 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-04-10 13:26:06 +0700 |
| commit | 539a2bc4e311ebf5ec3ed8b43d4b0fd433ccecbd (patch) | |
| tree | fe6bf2f21a12a174fc7c5ebbd070c197ebfde110 | |
| parent | 0dce304f59a437b369ff94a2ce31fbfe2f1e0258 (diff) | |
auto parsing lookup ip and looked last data parsing
| -rw-r--r-- | indoteknik_custom/models/ip_lookup.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/indoteknik_custom/models/ip_lookup.py b/indoteknik_custom/models/ip_lookup.py index 0fbb03ea..244982c0 100644 --- a/indoteknik_custom/models/ip_lookup.py +++ b/indoteknik_custom/models/ip_lookup.py @@ -41,12 +41,38 @@ class IpLookup(models.Model): logs = self.env['ip.lookup.line'].search(domain, limit=45, order='create_date asc') for log in logs: try: - ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json() - del ipinfo['status'] - log.lookup = json.dumps(ipinfo, indent=4, sort_keys=True) + query = [ + ('ip_address', '=', log.ip_address), + ('lookup', '!=', False) + ] + last_data = self.env['ip.lookup.line'].search(query, limit=1) + if last_data: + log.lookup = last_data.lookup + country = json.loads(last_data.lookup)['country'] + timezone = json.loads(last_data)['timezone'] + else: + ipinfo = requests.get('http://ip-api.com/json/%s' % log.ip_address).json() + del ipinfo['status'] + lookup_json = json.dumps(ipinfo, indent=4, sort_keys=True) + log.lookup = lookup_json + country = json.loads(lookup_json)['country'] + timezone = json.loads(lookup_json)['timezone'] + log.country = country + log.timezone = timezone + log.continent = timezone.split('/')[0] except: - log.lookup = '' + # log.lookup = '' + _logger.info('Failed parsing IP Lookup Line %s' % log.id) + def _load_info_address_lookup(self): + lines = self.env['ip.lookup.line'].search([('country', '=', False), ('lookup', '!=', False)], limit=500) + for line in lines: + line.country = json.loads(line.lookup)['country'] + timezone = json.loads(line.lookup)['timezone'] + continent = timezone.split('/')[0] + line.timezone = timezone + line.continent = continent + _logger.info('Success parsing ip lookup line id %s' % line.id) class IpLookupLine(models.Model): _name = 'ip.lookup.line' @@ -56,4 +82,5 @@ class IpLookupLine(models.Model): ip_address = fields.Char(string='IP Address') lookup = fields.Char(string='Lookup') country = fields.Char(string='Country') - + timezone = fields.Char(string='Timezone') + continent = fields.Char(string='Continent', help='diparsing dari field timezone') |
