This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!.env/bin/python | |
# -*- coding: utf-8 -*- | |
import csv | |
from db import db_session | |
from sqlalchemy import exc | |
from models import IPData | |
from datetime import datetime | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
# Create your models here. | |
class Location(models.Model): | |
""" | |
The Location data model for geo-coding | |
""" | |
ip_addr = models.CharField(max_length=15, null=False, blank=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework import serializers | |
from .models import Location | |
class LocationSerializer(serializers.Serializer): | |
id = serializers.ReadOnlyField() | |
ip_addr = serializers.CharField(required=True, allow_blank=False, max_length=15) | |
time_zone = serializers.CharField(required=True, allow_blank=False) | |
latitude = serializers.FloatField(required=True) | |
longitude = serializers.FloatField(required=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from rest_framework.urlpatterns import format_suffix_patterns | |
from . import views | |
urlpatterns = [ | |
path('', views.LocationList.as_view(), name='location-list'), | |
path('<int:pk>/', views.LocationDetail.as_view()), | |
path('geolocate/<str:ip_addr>', views.get_location, name='geolocate') | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from .models import Location | |
# Register your models here. | |
class LocationAdmin(admin.ModelAdmin): | |
list_display = ['ip_addr', 'region_name', 'country_name', 'time_zone', 'latitude', 'longitude'] | |
search_fields = ['ip_addr', 'region_name', 'latitude', 'longitude'] | |
list_filter = ['region_name', 'time_zone'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from .models import Location | |
from .serializers import LocationSerializer | |
from rest_framework.response import Response | |
from rest_framework import generics, permissions | |
from rest_framework import status | |
from rest_framework.decorators import api_view, permission_classes | |
from rest_framework.permissions import IsAuthenticated | |
import GeoIP | |
import ipaddress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.urls import path | |
from django.conf.urls import include | |
from django.conf import settings | |
from django.contrib import admin | |
from rest_framework_swagger.views import get_swagger_view | |
from .views import api_root | |
schema_view = get_swagger_view(title='DRF by Example') | |
# url list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, Response, abort, request, jsonify, g, url_for, render_template, flash | |
from flask_mail import Mail, Message | |
from flask_sslify import SSLify | |
from flask_sqlalchemy import SQLAlchemy | |
from flask_httpauth import HTTPTokenAuth | |
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer | |
from sqlalchemy import exc, and_, desc | |
from celery import Celery | |
from datetime import datetime | |
from db import db_session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from db import Base | |
from datetime import datetime | |
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean, Text, Float | |
from sqlalchemy.orm import relationship | |
from werkzeug.security import generate_password_hash, check_password_hash | |
import uuid | |
# Define application Bases | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/api/v1.0/sms/<string:phone_number>', methods=['GET']) | |
def get_sms_data(phone_number): | |
""" | |
Append data to Mobile Number | |
Return the Person obj by cell phone number | |
:param: string: phone_number | |
:return: obj(Person), type(json) | |
""" | |
geo, carrier, time_zone, city_geocode = range(4) |