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
def get_review_info(html: str): | |
tree = bs(html, 'lxml') | |
data = { | |
'id': _get_id_response_from_html(tree), | |
'link': _get_link_from_html(tree), | |
'title': _get_title_from_html(tree), | |
'city': _get_city_from_html(tree), | |
'bank_name': _get_bank_name_from_html(tree), | |
'score': _get_score_from_html(tree), | |
'status': _get_score_status_from_html(tree), |
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
create table if not exists home.dt_banki_responses ( | |
id int primary key, | |
link varchar(255) not null, | |
title varchar(255) not null, | |
city varchar(255) not null, | |
bank_name varchar(255) not null, | |
score integer null, | |
status varchar(100) null, | |
username varchar(100) null, | |
create_dt timestamptz not null, |
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
def insert_on_conflict(table: str, array: List, sql: str) -> None: | |
item = array[0] | |
columns = ', '.join(item.keys()) | |
dd = ["%s" for _ in range(len(item.keys()))] | |
placeholders = ", ".join(dd) | |
row = sql.format(table, columns, placeholders) | |
cursor.executemany(row, [tuple(item.values()) for item in array]) | |
conn.commit() |
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
insert into {} as t ({}) values ({}) on conflict (id) | |
do update set | |
title = excluded.title, | |
city = excluded.city, | |
bank_name = excluded.bank_name, | |
score = excluded.score, | |
status = excluded.status, | |
username = excluded.username, | |
create_dt = excluded.create_dt, | |
comments = excluded.comments, |
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
CREATE OR REPLACE FUNCTION _final_median(numeric[]) | |
RETURNS numeric AS | |
$$ | |
SELECT AVG(val) | |
FROM ( | |
SELECT val | |
FROM unnest($1) val | |
ORDER BY 1 | |
LIMIT 2 - MOD(array_upper($1, 1), 2) | |
OFFSET CEIL(array_upper($1, 1) / 2.0) - 1 |
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
select | |
avg(score) as avg_valie, median(score) as median_value | |
from | |
home.dt_banki_responses | |
where | |
date(create_dt) >= '2021-01-01'; |
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
select | |
substr(create_dt::varchar,1,7) as month | |
, round(avg(score), 1) as "Среднее" | |
, trunc(median(score)) as "Медиана" | |
, count(*) as "Общее кол-во" | |
, sum(case when score = 1 then 1 else 0 end) as "Оценка 1" | |
, sum(case when score = 2 then 1 else 0 end) as "Оценка 2" | |
, sum(case when score = 3 then 1 else 0 end) as "Оценка 3" | |
, sum(case when score = 4 then 1 else 0 end) as "Оценка 4" | |
, sum(case when score = 5 then 1 else 0 end) as "Оценка 5" |
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
select | |
status as "Статус" | |
, count(*) as "Кол-во" | |
from | |
home.dt_banki_responses | |
where | |
date(create_dt) >= '2021-01-01' | |
group by status | |
order by 2 desc; |
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
select | |
status as "Статус" | |
, count(*) as "Кол-во" | |
, sum(case when score = 1 then 1 else 0 end) as "Оценка 1" | |
, sum(case when score = 2 then 1 else 0 end) as "Оценка 2" | |
, sum(case when score = 3 then 1 else 0 end) as "Оценка 3" | |
, sum(case when score = 4 then 1 else 0 end) as "Оценка 4" | |
, sum(case when score = 5 then 1 else 0 end) as "Оценка 5" | |
, sum(case when score is null then 1 else 0 end) as "Без оценки" | |
from |
OlderNewer