Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions csvtry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import csv

fields = ['Name', 'Branch', 'Year', 'CGPA']

# data rows of csv file
rows = [ ['Nikhil', 'COE', '2', '9.0'],
['Sanchit', 'COE', '2', '9.1'],
['Aditya', 'IT', '2', '9.3'],
['Sagar', 'SE', '1', '9.5'],
['Prateek', 'MCE', '3', '7.8'],
['Sahil', 'EP', '2', '9.1']]

# name of csv file
filename = "university_records.csv"

# writing to csv file
with open(filename, 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)

# writing the fields
csvwriter.writerow(fields)

# writing the data rows
csvwriter.writerows(rows)


fields = []
rows = []

# reading csv file
with open(filename, 'r') as csvfile:
# creating a csv reader object
csvreader = csv.reader(csvfile)

# extracting field names through first row
fields = next(csvreader)
# extracting each data row one by one
for row in csvreader:
rows.append(row)

# get total number of rows
print("Total no. of rows: %d"%(csvreader.line_num))

# printing the field names
print('Field names are:\n' + ' '.join(field for field in fields))


for row in rows[:5]:
# parsing each column of a row
for col in row:
print("%10s"%col)
print('\n')
52 changes: 52 additions & 0 deletions nearby.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import requests

#now 2 tasks

# 1 change the whole program to Object oriented style
# e.g. a = GoogleMapPlaces("Chittorgarh", "1500", "Pizza", "") should create object
# a.getNearByAddress() should give result


# 2 Get your own API Key from google cloud console
# open terminal arey baba yaha pr
class GoogleMapPlaces:
API_KEY = "AIzaSyDZMs9AfgNI0fcvENgUK6pM6lS3wbptcbE"

def __init__(self, address, radius, type, keyword):
self.address = address
self.radius = radius
self.type = type
self.keyword = keyword


def addressToCoordinates(self):
url = "https://maps.googleapis.com/maps/api/geocode/json"

querystring = {"address":self.address,"key":self.API_KEY}


response = requests.request("GET", url, params=querystring)

# check if response is 'ok' then return result
if response.json()["status"]=="OK":
return response.json()["results"][0]["geometry"]["location"]
else:
print(response.text)
return { "error": "Not found"}

def getNearBy(self):
location = self.addressToCoordinates()
x= location["lat"]
y= location["lng"]
loc=str(x)+","+str(y)
url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"

querystring = {"location":loc,"radius":self.radius,"type":self.type,"keyword":self.keyword,"key":self.API_KEY}

response = requests.request("GET", url, params=querystring)
return response.json()

def getNearByAddress(self):
r = self.getNearBy()
for x in r["results"]:
print(x["name"]+" "+x.get("vicinity", ""))
2 changes: 2 additions & 0 deletions src/proj/proj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'r3po',
'rest_framework',
'webapp'
]

MIDDLEWARE = [
Expand Down
3 changes: 3 additions & 0 deletions src/proj/proj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"""
from django.conf.urls import url
from django.contrib import admin
from rest_framework.urlpatterns import format_suffix_patterns
from webapp import views

urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^Product/', views.productList.as_view()),
]
Empty file added src/proj/webapp/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions src/proj/webapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from . models import Product

# Register your models here.
admin.site.register(Product)

5 changes: 5 additions & 0 deletions src/proj/webapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class WebappConfig(AppConfig):
name = 'webapp'
24 changes: 24 additions & 0 deletions src/proj/webapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.0.4 on 2018-06-24 04:57

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('product_id', models.IntegerField(null=True)),
('name', models.CharField(max_length=5000, null=True)),
('mrp', models.CharField(max_length=10, null=True)),
('discountprice', models.CharField(max_length=10, null=True)),
],
),
]
Empty file.
12 changes: 12 additions & 0 deletions src/proj/webapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models
from django.contrib.postgres import fields as pg

# Create your models here.
class Product(models.Model):
product_id = models.IntegerField(null=True)
name = models.CharField(max_length=5000, null=True)
mrp = models.CharField(max_length=10,null=True)
discountprice = models.CharField(max_length=10,null=True)

def __str__(self):
return self.name
8 changes: 8 additions & 0 deletions src/proj/webapp/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from . models import Product

class ProductSerializer(serializers.ModelSerializer):

class Meta:
model = Product
fields = '__all__'
3 changes: 3 additions & 0 deletions src/proj/webapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
20 changes: 20 additions & 0 deletions src/proj/webapp/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.shortcuts import render

# Create your views here.
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from . models import Product
from . serializers import ProductSerializer

class productList(APIView):

def get(self, request):
product1 = Product.objects.all()
serializer = ProductSerializer(product1, many = True)
return Response(serializer.data)

def post(self):
pass