#!.venv/bin/python from db_con import DbConnect from matplotlib import pyplot as plt from datetime import date import csv con = DbConnect("olx_data.db") con.get_connection() query = """ select * from olx_data; """ data = con.get_data(query) dates = [] rent = [] sell = [] exchange = [] for i in data: sell.append(i[3]) rent.append(i[4]) exchange.append(i[5]) dates.append(date.fromisoformat(i[6])) if len(dates) >= 7: plt.plot(dates[-7:], rent[-7:], label="wynajem") plt.plot(dates[-7:], sell[-7:], label="sprzedaż") plt.plot(dates[-7:], exchange[-7:], label="zamiana") plt.xlabel("data") plt.xticks(rotation=45) plt.ylabel("ilość ogłoszeń") plt.title("ogłoszenia o mieszkaniach na olx.pl (ostatnie 7 dni)") plt.legend() plt.savefig("week.jpg", bbox_inches="tight", dpi=150) plt.cla() if len(dates) >= 30: plt.plot(dates[-30:], rent[-30:], label="wynajem") plt.plot(dates[-30:], sell[-30:], label="sprzedaż") plt.plot(dates[-30:], exchange[-30:], label="zamiana") plt.xlabel("data") plt.xticks(rotation=45) plt.ylabel("ilość ogłoszeń") plt.title("ogłoszenia o mieszkaniach na olx.pl (ostatnie 30 dni)") plt.legend() plt.savefig("month.jpg", bbox_inches="tight", dpi=150) plt.cla() if len(dates) >= 90: threemonths.plot(dates[-90:], rent[-90:], label="wynajem") threemonths.plot(dates[-90:], sell[-90:], label="sprzedaż") threemonths.plot(dates[-90:], exchange[-90:], label="zamiana") threemonths.xlabel("data") threemonths.xticks(rotation=45) threemonths.ylabel("ilość ogłoszeń") threemonths.title("ogłoszenia o mieszkaniach na olx.pl (ostatnie 90 dni)") threemonths.legend() threemonths.savefig("threemonths.jpg", bbox_inches="tight", dpi=150) cursor=con.connection.cursor() cursor.execute("SELECT * FROM olx_data;") with open("data.csv", "w") as datacsv: csv_out = csv.writer(datacsv) csv_out.writerow([d[0] for d in cursor.description]) for result in cursor: csv_out.writerow(result) cursor.close()