def register_visit(site_id): site = Site.get_by_id(site_id) if site: browser = request.headers.get('User-Agent') date = datetime.now() event = request.args.get('event') url = request.url ip_address = request.remote_addr geo = get_geodata(ip_address) location_full = ", ".join([geo['city'],geo['zipcode'],geo['latitude'],geo['longitude']]) location = ", ".join([geo['city'],geo['zipcode']]) visit = Visit(browser, date, event, url, ip_address, location_full, location) visit.site_id = site_id db.session.add(visit) db.session.commit() return Response("visit recorded", content_type="text/plain")
def register_visit(site_id): site = Site.get_by_id(site_id) if site: browser = request.headers.get('User-Agent') date = datetime.now() event = request.args.get('event') url = request.url ip_address = request.remote_addr geo = get_geodata(ip_address) location_full = ", ".join( [geo['city'], geo['zipcode'], geo['latitude'], geo['longitude']]) location = ", ".join([geo['city'], geo['zipcode']]) visit = Visit(browser, date, event, url, ip_address, location_full, location) visit.site_id = site_id db.session.add(visit) db.session.commit() return Response("visit recorded", content_type="text/plain")
"regioncode": csv_data[4], "regionname": csv_data[5], "city": csv_data[6], "zipcode": csv_data[7], "latitude": csv_data[8], "longitude": csv_data[9] } def get_geodata(ip): return __get_geodata_csv(ip) if __name__ == "__main__": #code to execute if called from command-line intput_ip = sys.argv[1] geodata = get_geodata(intput_ip) print "IP: %s" % geodata["ip"] print "Country Code: %s" % geodata["countrycode"] print "Country Name: %s" % geodata["countryname"] print "Region Code: %s" % geodata["regioncode"] print "Region Name: %s" % geodata["regionname"] print "City: %s" % geodata["city"] print "Zip Code: %s" % geodata["zipcode"] print "Latitude: %s" % geodata["latitude"] print "Longitude: %s" % geodata["longitude"] ########NEW FILE######## __FILENAME__ = models from app import db from app.mixins import CRUDMixin
"countrycode":csv_data[2], "countryname":csv_data[3], "regioncode":csv_data[4], "regionname":csv_data[5], "city":csv_data[6], "zipcode":csv_data[7], "latitude":csv_data[8], "longitude":csv_data[9] } def get_geodata(ip): return __get_geodata_csv(ip) if __name__ == "__main__": #code to execute if called from command-line intput_ip = sys.argv[1] geodata = get_geodata(intput_ip) print "IP: %s" % geodata["ip"] print "Country Code: %s" % geodata["countrycode"] print "Country Name: %s" % geodata["countryname"] print "Region Code: %s" % geodata["regioncode"] print "Region Name: %s" % geodata["regionname"] print "City: %s" % geodata["city"] print "Zip Code: %s" % geodata["zipcode"] print "Latitude: %s" % geodata["latitude"] print "Longitude: %s" % geodata["longitude"] ########NEW FILE######## __FILENAME__ = models from app import db from app.mixins import CRUDMixin class Site(CRUDMixin, db.Model):