28
loading...
This website collects cookies to deliver better user experience
DB_NAME
, DB_USERNAME
and DB_PASSWORD
.my-super-project
hellothisisapasswordandihopeitsstrongenough2021
West EU (London)
CREATE TABLE public.conv
(
id uuid NOT NULL DEFAULT uuid_generate_v4(),
sender character varying COLLATE pg_catalog."default",
receiver character varying COLLATE pg_catalog."default",
content text COLLATE pg_catalog."default",
datetime timestamp with time zone DEFAULT now(),
CONSTRAINT conv_pkey PRIMARY KEY (id)
) TABLESPACE pg_default;
COMMENT ON COLUMN public.conv.sender
IS 'the one who sends the message';
COMMENT ON COLUMN public.conv.receiver
IS 'the one supposed to receive the message';
COMMENT ON COLUMN public.conv.content
IS 'the actual message';
COMMENT ON COLUMN public.conv.datetime
IS 'the date time the sender sends the content to the receiver';
ALTER TABLE ONLY public.conv ADD CONSTRAINT conv_pkey PRIMARY KEY (id);
d5f67084-c0ca-4ae5-8957-348237ba51be A B Hey! It's been a while. How you're doing? 2021-06-26 12:03:22+00
5287170c-b6f6-47fe-ad0c-9f724ef60acb B A Hey.\nThanks for your message. I'm doing fine, thanks!\nWhat's up? 2021-06-26 12:03:31+00
1c927c51-dd2f-4f1c-9ead-609f71b7747e A B Nothing much. Wanna hang out tonight? 2021-06-26 12:04:10+00
f243838c-1596-46d1-86d5-304def0840db B A Sure, I must be free at 7pm. What was the name of the bar we used to hang out in? 2021-06-26 12:04:50+00
a3ce9c80-8333-4fc7-8d27-7c19c31326d4 A B Foo. The Foo Bar. 2021-06-26 12:05:45+00
8f990cc9-35e7-4fa8-baac-d87bcf9f213e B A Oh, yeah. How could I forget something that is so obvious. LOL 2021-06-26 12:06:14+00
02c18b5f-098e-479e-bcf5-42946cf34fe1 A B See you there btw, is 7:30pm ok for you? 2021-06-26 12:07:02+00
6fb02446-263d-4bf9-bdc1-51ad7f03c40c B A Perfect. See you! 2021-06-26 12:07:23+00
postgres(ql)://user:[email protected]:portnumber/dbname
.SELECT * FROM NAMETABLE
), and gives back the datas as JSON. It’s actually a REST API controller.python-server
for example. From now on, you will need to create 5 files. 2 of those 5 files will be auto-generated , you will read more about it later, just right herepython-server
in our example), copy and paste the :cert.pem
key.pem
python app.py
then go to:https://127.0.0.1:5000/<YOUR-DB-HOST>/<YOUR-SELECT-STATEMENT>
python-server-heroku
.python-server-heroku
. Once the repo is found, click on Connect.Procfile
file will help your app to run on the web and scale:web: gunicorn app:app
heroku ps:scale worker=1
<YOUR-HEROKU-APP>.herokuapp.com/<YOUR-DB-HOST>/<YOUR-SELECT-STATEMENT>
and see the datas displaying as JSON object.conv
. Open a new tab for the next and very last step.Code.gs
file:const URL_OF_THE_SPREADSHEET = "https://docs.google.com/spreadsheets/d/1QMEr6ABZpLqo8d0h_nY4BCu3hdE0Bkbo-Zj7qgp37Qw/edit#gid=0" //to be changed
const URL_OF_HEROKU_APP = "https://python-server-heroku.herokuapp.com/db.ehbnuyfpyplmhgjshzmd.supabase.co/SELECT%20*%20FROM%20conv" //to be changed
const ss = SpreadsheetApp.openByUrl(URL_OF_THE_SPREADSHEET)
function go(){
update_my_sheet("conv")
}
function getJSONDataFromUrl(url,params) {
console.log(url)
if(!params) params = {}
params['muteHttpExceptions'] = true
params['method'] = "GET"
var response = UrlFetchApp.fetch(url, params);
var parsedJsonData = JSON.parse(response.getContentText());
return parsedJsonData;
}
function update_my_sheet(sheet_name){
var url_to_be_fetched = URL_OF_HEROKU_APP
var initial_results = getJSONDataFromUrl(url_to_be_fetched)
//clear everything at the beginning
var sheet = ss.getSheetByName(sheet_name);
sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns()).clear({contentsOnly: true});
//no datas found
if(initial_results.length === 0) return false
var results = initial_results.map(it => Object.values(it))
var headers = Object.keys(initial_results[0])
var rows_number = Number(results.length)
var columns_number = results[0].length
set_headers(sheet_name, headers)
//2nd row cause we have the headers in 1st row
var range = sheet.getRange(2,1,rows_number, columns_number);
range.setValues(results);
}
function set_headers(sheet_name, headers){
var last_column_address = columnToLetter(headers.length)
ss.getSheetByName(sheet_name).getRange("A1:"+last_column_address+"1").setValues([headers]);
}
function columnToLetter(column)
{
var temp, letter = '';
while (column > 0)
{
temp = (column - 1) % 26;
letter = String.fromCharCode(temp + 65) + letter;
column = (column - temp - 1) / 26;
}
return letter;
}
URL_OF_THE_SPREADSHEET
and URL_OF_HEROKU_APP
from the code above.