initial api setup
This commit is contained in:
parent
c95ba33e04
commit
2447e8c222
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
||||||
|
*.csv
|
||||||
|
.idea/
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|
0
apiv1/__init__.py
Normal file
0
apiv1/__init__.py
Normal file
3
apiv1/admin.py
Normal file
3
apiv1/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
apiv1/apps.py
Normal file
5
apiv1/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class Apiv1Config(AppConfig):
|
||||||
|
name = 'apiv1'
|
0
apiv1/migrations/__init__.py
Normal file
0
apiv1/migrations/__init__.py
Normal file
3
apiv1/models.py
Normal file
3
apiv1/models.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
8
apiv1/serializers.py
Normal file
8
apiv1/serializers.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from rest_framework import serializers
|
||||||
|
from scraper.models import Instance
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Instance
|
||||||
|
fields = ('name', 'peers')
|
3
apiv1/tests.py
Normal file
3
apiv1/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
11
apiv1/views.py
Normal file
11
apiv1/views.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
from rest_framework import viewsets
|
||||||
|
from scraper.models import Instance
|
||||||
|
from apiv1.serializers import InstanceSerializer
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceViewSet(viewsets.ModelViewSet):
|
||||||
|
"""API endpoint to view instance details"""
|
||||||
|
queryset = Instance.objects.all()
|
||||||
|
serializer_class = InstanceSerializer
|
||||||
|
|
|
@ -37,6 +37,9 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
|
'scraper.apps.ScraperConfig',
|
||||||
|
'apiv1.apps.Apiv1Config',
|
||||||
|
'rest_framework',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
|
@ -13,9 +13,13 @@ Including another URLconf
|
||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
from django.contrib import admin
|
from django.urls import path, include
|
||||||
from django.urls import path
|
from rest_framework import routers
|
||||||
|
from apiv1 import views
|
||||||
|
|
||||||
|
router = routers.DefaultRouter()
|
||||||
|
router.register(r'instances', views.InstanceViewSet)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path(r'', include(router.urls))
|
||||||
]
|
]
|
||||||
|
|
8
requirements.txt
Normal file
8
requirements.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
certifi==2018.8.24
|
||||||
|
chardet==3.0.4
|
||||||
|
Django==2.1
|
||||||
|
djangorestframework==3.8.2
|
||||||
|
idna==2.7
|
||||||
|
pytz==2018.5
|
||||||
|
requests==2.19.1
|
||||||
|
urllib3==1.23
|
0
scraper/__init__.py
Normal file
0
scraper/__init__.py
Normal file
3
scraper/admin.py
Normal file
3
scraper/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
5
scraper/apps.py
Normal file
5
scraper/apps.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ScraperConfig(AppConfig):
|
||||||
|
name = 'scraper'
|
36
scraper/migrations/0001_initial.py
Normal file
36
scraper/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# Generated by Django 2.1 on 2018-08-26 00:29
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Instance',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=200)),
|
||||||
|
('peers', models.ManyToManyField(related_name='followers', to='scraper.Instance')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='InstanceStats',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('timestamp', models.DateTimeField(auto_now_add=True)),
|
||||||
|
('num_peers', models.IntegerField()),
|
||||||
|
('num_statuses', models.IntegerField()),
|
||||||
|
('num_users', models.IntegerField()),
|
||||||
|
('version', models.CharField(max_length=1000)),
|
||||||
|
('status', models.CharField(max_length=100)),
|
||||||
|
('instance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='scraper.Instance')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
0
scraper/migrations/__init__.py
Normal file
0
scraper/migrations/__init__.py
Normal file
19
scraper/models.py
Normal file
19
scraper/models.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Instance(models.Model):
|
||||||
|
name = models.CharField(max_length=200)
|
||||||
|
peers = models.ManyToManyField('self', related_name='followers', symmetrical=False)
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceStats(models.Model):
|
||||||
|
timestamp = models.DateTimeField(auto_now_add=True)
|
||||||
|
instance = models.ForeignKey(
|
||||||
|
'Instance',
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
)
|
||||||
|
num_peers = models.IntegerField()
|
||||||
|
num_statuses = models.IntegerField()
|
||||||
|
num_users = models.IntegerField()
|
||||||
|
version = models.CharField(max_length=1000)
|
||||||
|
status = models.CharField(max_length=100)
|
3
scraper/tests.py
Normal file
3
scraper/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
3
scraper/views.py
Normal file
3
scraper/views.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
Loading…
Reference in a new issue