Initial Commit
This commit is contained in:
commit
4e6b812f98
63
gsheet_to_json_data.postman_collection.json
Normal file
63
gsheet_to_json_data.postman_collection.json
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
{
|
||||||
|
"info": {
|
||||||
|
"_postman_id": "57361606-e010-4061-9e4e-daa7692455de",
|
||||||
|
"name": "gsheet_to_json_data",
|
||||||
|
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||||
|
"_exporter_id": "27087263"
|
||||||
|
},
|
||||||
|
"item": [
|
||||||
|
{
|
||||||
|
"name": "sample",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [],
|
||||||
|
"url": {
|
||||||
|
"raw": "http://127.0.0.1:5000/sample",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"127",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"port": "5000",
|
||||||
|
"path": [
|
||||||
|
"sample"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "gsheet_to_json_data",
|
||||||
|
"request": {
|
||||||
|
"method": "POST",
|
||||||
|
"header": [],
|
||||||
|
"body": {
|
||||||
|
"mode": "raw",
|
||||||
|
"raw": "{\n \"requestid\":\"2838123671\",\n \"requesttype\":\"listdata\",\n \"requestsrc\":\"ui\",\n \"requestdata\":{\n \"sheet_url\" : \"https://docs.google.com/spreadsheets/d/1EQy3mawrPO3bLmurxaf8bR0WhTZS9-uXT2773Bb9B5Y/edit#gid=0\"\n }\n}",
|
||||||
|
"options": {
|
||||||
|
"raw": {
|
||||||
|
"language": "json"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"url": {
|
||||||
|
"raw": "http://127.0.0.1:5000/data",
|
||||||
|
"protocol": "http",
|
||||||
|
"host": [
|
||||||
|
"127",
|
||||||
|
"0",
|
||||||
|
"0",
|
||||||
|
"1"
|
||||||
|
],
|
||||||
|
"port": "5000",
|
||||||
|
"path": [
|
||||||
|
"data"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"response": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
13
project-g-sheet-to-json-b23cf6e187cd.json
Normal file
13
project-g-sheet-to-json-b23cf6e187cd.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"type": "service_account",
|
||||||
|
"project_id": "project-g-sheet-to-json",
|
||||||
|
"private_key_id": "b23cf6e187cde197053bbf5e8428d728808adf7f",
|
||||||
|
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDDgwCCXLjl0uke\n4g9U4wPkDpdHhn9sznQmhR5FR2omN9xKMT59e0SrDiKXs0hNQX6lQE+ewzsdfpby\nO88doja8uKhmti0wfL6OEnxGDAHIt92Whgaux/ho1lNOp/EjBQfTNWwACn+1x/iA\nwFZzxjQCKvj8PJ7IsqHgV1SmXWB9956msdUUP7LB6lD9Vy0wVhAZD6xAEDXXbel7\nI535JPZLgGTs9/JDBHx/TjtpfVrjRpfqACvdYC1MhAbUmZX7xRbMRmB7C226gPJF\nZotaYsVlA9EotK+CXcU2fTslRyISGAa/+fVdgePXLfrZBz/JhhF3TRjGN56QIIu5\nQ0gjl1kHAgMBAAECggEAF9/wePrfrVkDFL1gR+ps+DV77cUT3HKdpnKNDsK4yK/7\nm6fFzMb3zLeuK7497wk3cPCYiHeoyWJDBpOdKC495u/ZyKkofYpOLsU9HcSrlxo0\n2gPF3yQWRp8djzZc8PzVRsp4RM0DaWxhAT/7jqm+giFDRHIWpcWClQW1FZfDh741\nnnezlJ2J3r2hd9yBLbKBLs6bNDAiGg0A2zCxdohbDEKmlMC+xWfhVkyVSl1hjwBk\nUj4NCBOIBNsR7AGWgyFqb+rDFwnxTD/YzG1NfOu8xzseXOjiyaPwpk06VzJJCHkz\nBK56kl+LGxVFjLacWnPnsh5A6+q3P4VldtF6YxiomQKBgQDlS4sXrKWZQXQk4Rb3\nRYKJZx+Gum6PjP6uWf41g2W6sUK2Yk3sKMq+n4dS5QuMehbazko4C/yOKj5EX25I\nL91yVW0BEPKw9f4Y1eLUvPLo0oFpzDzH1NqleMwG2GK8N01pRoVj9wY1364IUHm2\nkjDp76Le5918LlbU9Xi9dSj2iwKBgQDaSDRE7X/7XDQDsZqLIHr0iCsh0WZ2ZhnL\nQuA6pVnYIdDU6hLtf7PhT6Q/FBz5/5BM15B8VrJ4EGubyCE2CdX/tyN9Gw2gc7ye\nP8DQKo+SQ+LcTvYjq6I1AVnK4uVZpJiqh4OgT7xob9OblyqQH58KvXA7A8H2S4Dx\nEnOXfXzy9QKBgQDh6W4fYzC9MGn4M/VmpwuXyQyct25a7PW4Xl5B5zYBnMg33d8c\nQIyRB6hSmeyo+VkvN3SUh+rLPv+eac/EO7SZA2WkWUhj5dn2KjWUmJ1TmqN604lG\n8YaC5eNPEz8kZfBVOvANr8Jkrf9PncptgNfEhSAZMqVbxmQy6a+OKrKzRQKBgQC/\nrF+ZlyOmyVQzWiVmveK6D0gwrfvXQ9iqj9LuLHw0OZ1zGQf93QFLe++yJCs9q5g+\noZuSU17r5x9W7+mZ1hFANsTG+paAqqCaJUlegcEIouv2oK+qqvAIs2LxsUPL76jP\nNafzgZDj9C5QlfEeFWZGvAptB+OuLqbPCXDPObYacQKBgQCW2hOBDLfKCJiVmIT8\nRzEUDo2X8J7wr+QZEBuP87hBNe9gufvwpVYDygAo+nCmvG0g2rSvr7kIwNlCC7Y2\nVXHSnIxL/lccQzW/MsFJhsnTGp3AMKsh5koZx6BsI6+mKwkxcW7VoFWLuXyv9WwR\nXBlEMbP5ukUmpgDBsbey+LoiDg==\n-----END PRIVATE KEY-----\n",
|
||||||
|
"client_email": "gsheettojson@project-g-sheet-to-json.iam.gserviceaccount.com",
|
||||||
|
"client_id": "105366380300754948511",
|
||||||
|
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||||
|
"token_uri": "https://oauth2.googleapis.com/token",
|
||||||
|
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||||
|
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gsheettojson%40project-g-sheet-to-json.iam.gserviceaccount.com",
|
||||||
|
"universe_domain": "googleapis.com"
|
||||||
|
}
|
44
server.py
Normal file
44
server.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
from flask import Flask, jsonify, request
|
||||||
|
import gspread
|
||||||
|
from oauth2client.service_account import ServiceAccountCredentials
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
@app.route('/sample',methods=['POST'])
|
||||||
|
def get_sample_data():
|
||||||
|
return {"name" : "Ganesh kumar"}
|
||||||
|
|
||||||
|
@app.route('/data', methods=['POST'])
|
||||||
|
def get_data():
|
||||||
|
reqData = request.json
|
||||||
|
request_data = reqData['requestdata']
|
||||||
|
try:
|
||||||
|
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
||||||
|
credentials = ServiceAccountCredentials.from_json_keyfile_name('project-g-sheet-to-json-b23cf6e187cd.json', scope)
|
||||||
|
client = gspread.authorize(credentials)
|
||||||
|
sheet_url = request_data['sheet_url']
|
||||||
|
|
||||||
|
spreadsheet = client.open_by_url(sheet_url)
|
||||||
|
|
||||||
|
sheet_data = {}
|
||||||
|
|
||||||
|
for sheet in spreadsheet:
|
||||||
|
sheet_name = sheet.title
|
||||||
|
data = sheet.get_all_records()
|
||||||
|
sheet_data[sheet_name] = data
|
||||||
|
|
||||||
|
|
||||||
|
# sheet = client.open_by_url(sheet_url).sheet1
|
||||||
|
# data = sheet.get_all_records()
|
||||||
|
respsucc={"responseid": reqData['requestid'], "responsefor": "Sheet Details", "responsesetto": "UI", "response": {"message": "Success", "data" : sheet_data}}
|
||||||
|
print(data)
|
||||||
|
return jsonify(respsucc)
|
||||||
|
except Exception as e:
|
||||||
|
respfail = {"responseid": reqData['requestid'], "responsefor": "Sheet Details", "responsesetto": "UI", "response": {"message": e}}
|
||||||
|
return jsonify(respfail)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Running app
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run(host="0.0.0.0",debug=True)
|
Loading…
Reference in New Issue
Block a user