Skip to content

Commit

Permalink
add insights
Browse files Browse the repository at this point in the history
  • Loading branch information
shayki5 committed Oct 30, 2023
1 parent f60ed12 commit 052f1f8
Show file tree
Hide file tree
Showing 3 changed files with 306 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node_modules/

# dotenv environment variables file
.env

google.json
local_config/
dst/
output
output
135 changes: 135 additions & 0 deletions gpt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import openai
import gspread
import urllib.request
from oauth2client.service_account import ServiceAccountCredentials
from bidi.algorithm import get_display
from urllib.parse import quote
from datetime import datetime, timedelta
from collections import defaultdict
import operator

# Set up Google Sheets API credentials
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name(
"google.json", scope
)
client = gspread.authorize(creds)

def create_new_sheet():
spreadsheet = client.open('ניסיון')
current_date = datetime.now()
first_day_of_current_month = current_date.replace(day=1)
last_day_of_previous_month = first_day_of_current_month - timedelta(days=1)
formatted_date = last_day_of_previous_month.strftime("%m/%y")
worksheet = spreadsheet.worksheet('current')
worksheet.update_title(formatted_date)
new_sheet = spreadsheet.add_worksheet(title='current', rows=300, cols=11)
column_titles = [
'date', 'amount', 'description', 'memo', 'category', 'account',
'hash', 'comment', 'scraped at', 'scraped by', 'identifier'
]

new_sheet.update('A1:O1', [column_titles])
print("New sheet created successfully!")

spreadsheet = client.open('ניהול הוצאות הבית 2023')
source_sheet = spreadsheet.worksheet('נוכחי')
new_sheet = spreadsheet.duplicate_sheet(source_sheet.id, new_sheet_name=formatted_date)
cell_formula = new_sheet.cell(3, 3, value_render_option='FORMULA').value
new_formula = cell_formula.replace('current', formatted_date)
new_sheet.update_cell(3, 3, new_formula)
cell_formula = new_sheet.cell(3, 4, value_render_option='FORMULA').value
new_formula = cell_formula.replace('current', formatted_date)
new_sheet.update_cell(3, 4, new_formula)
cell_formula = new_sheet.cell(3, 5, value_render_option='FORMULA').value
new_formula = cell_formula.replace('current', formatted_date)
new_sheet.update_cell(3, 5, new_formula)

# clear מזומן
range_to_clear = 'G3:G30'
source_sheet.batch_clear([range_to_clear])

values = [["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"], ["~"]]
source_sheet.update("F3:F30", values)


def sum_category(sheet_name, sheet_title):
sheet = client.open(sheet_name).worksheet(sheet_title)
categories = defaultdict(float)
for row in sheet.get_all_records():
print(row['amount'])
if row['amount']:
amount = int(row['amount'])
else:
print("can't convert to int")
category = row['category']
categories[category] += amount
sorted_categories = sorted(categories.items(), key=operator.itemgetter(1), reverse=True)
message = ""
message = u"✨ הוצאות לפי קטגוריות ✨\n"
for category, total in sorted_categories:
message += f"{category}: {total}\n"
print(message)
message_encoded = quote(message)

contents = urllib.request.urlopen("https://api.callmebot.com/whatsapp.php?phone=+972587994574&text=" + message_encoded + "&apikey=1236970").read()

def check_transactions(sheet_name, sheet1_title, sheet2_title):
# Open the Google Sheet
sheet1 = client.open(sheet_name).worksheet(sheet1_title)
sheet2 = client.open(sheet_name).worksheet(sheet2_title)

# Get all the values from both sheets
values_sheet1 = sheet2.get_all_values()
values_sheet2 = sheet1.get_all_values()

# Assuming the data includes supplier and amount columns, you can extract them
supplier_column = 3
amount_column = 2

# Create dictionaries to store transactions by supplier and their amounts
transactions_sheet1 = {}
transactions_sheet2 = {}

# Create a dictionary to keep track of the occurrences of each supplier
supplier_count = {}

# Populate the dictionaries from Sheet 1
for row in values_sheet1[2:]: # Skip the header row
supplier = row[supplier_column]
amount = float(row[amount_column])
transactions_sheet1[supplier] = amount
supplier_count[supplier] = supplier_count.get(supplier, 0) + 1

# Initialize a message to store the result
message = u"✨ הוצאות החודש שיותר גבוהות מחודש שעבר ✨\n"

# Compare transactions in Sheet 2 with Sheet 1
for row in values_sheet2[2:]: # Skip the header row
supplier = row[supplier_column]
amount = float(row[amount_column])
if supplier in transactions_sheet1 and supplier_count[supplier] == 1 and amount > transactions_sheet1[supplier]:
message += f"עסקה מספק '{supplier}' בחודש '{sheet1_title}' עם סכום גבוה יותר מחודש '{sheet2_title}': {amount} > {transactions_sheet1[supplier]}\n"
message_display = get_display(message)

# Check if any such transactions were found
if message_display:
message
result_message_encoded = quote(message)
contents = urllib.request.urlopen("https://api.callmebot.com/whatsapp.php?phone=+972587994574&text=" + result_message_encoded + "&apikey=1236970").read()
else:
print("No transactions found in '{sheet2_title}' with higher amounts compared to '{sheet1_title}'.")

#sum_category("ניסיון", "current")

sheet_name = "ניהול הוצאות הבית 2023"
sheet1_title = "נוכחי"
current_date = datetime.now()
first_day_of_current_month = current_date.replace(day=1)
last_day_of_previous_month = first_day_of_current_month - timedelta(days=1)
formatted_date = last_day_of_previous_month.strftime("%m/%y")
print(formatted_date)
sheet2_title = formatted_date
#check_transactions(sheet_name, sheet1_title, sheet2_title)

create_new_sheet()
169 changes: 169 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
abstract_singleton==1.0.1
aiohttp==3.8.4
aiosignal==1.3.1
anyio==3.6.2
async-generator==1.10
async-timeout==4.0.2
asynctest==0.13.0
attrs==23.1.0
auto_gpt_plugin_template==0.0.3
autoflake==2.1.1
beautifulsoup4==4.12.2
black==23.3.0
blinker==1.6.2
blis==0.7.9
cachetools==5.3.0
catalogue==2.0.8
certifi==2023.5.7
cffi==1.15.1
cfgv==3.3.1
chardet==5.1.0
charset-normalizer==3.1.0
click==8.1.3
colorama==0.4.6
confection==0.0.4
contourpy==1.1.1
coverage==7.2.5
cryptography==40.0.2
cssselect==1.2.0
cycler==0.12.1
cymem==2.0.7
diskcache==5.6.1
distlib==0.3.6
distro==1.8.0
dnspython==2.3.0
docker==6.1.0
docutils==0.20.1
duckduckgo-search==2.9.3
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl
exceptiongroup==1.1.1
filelock==3.12.0
flake8==6.0.0
Flask==2.3.2
flask-swagger==0.2.14
fonttools==4.43.1
frozenlist==1.3.3
ghp-import==2.1.0
gitdb==4.0.10
GitPython==3.1.31
google-api-core==2.11.0
google-api-python-client==2.86.0
google-auth==2.17.3
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.1.0
googleapis-common-protos==1.59.0
gspread==5.11.3
gTTS==2.3.1
h11==0.14.0
httpcore==0.17.0
httplib2==0.22.0
httpx==0.24.0
identify==2.5.24
idna==3.4
iniconfig==2.0.0
isort==5.12.0
itsdangerous==2.1.2
Jinja2==3.1.2
jsonify==0.5
jsonschema==4.17.3
kiwisolver==1.4.5
langcodes==3.3.0
loguru==0.7.0
lxml==4.9.2
Markdown==3.3.7
MarkupSafe==2.1.2
matplotlib==3.8.0
mccabe==0.7.0
mergedeep==1.3.4
mkdocs==1.4.3
multidict==6.0.4
murmurhash==1.0.9
mypy-extensions==1.0.0
nodeenv==1.7.0
numpy==1.26.1
oauth2client==4.1.3
oauthlib==3.2.2
openai==0.27.2
openapi-python-client==0.13.4
orjson==3.8.10
outcome==1.2.0
packaging==23.1
pandas==2.1.2
pathspec==0.11.1
pathy==0.10.1
Pillow==9.5.0
pinecone-client==2.2.1
platformdirs==3.5.0
playsound==1.2.2
pluggy==1.0.0
pre-commit==3.3.1
preshed==3.0.8
protobuf==4.22.4
py-cpuinfo==9.0.0
pyasn1==0.5.0
pyasn1-modules==0.3.0
pybind11==2.10.4
pycairo==1.23.0
pycodestyle==2.10.0
pycparser==2.21
pydantic==1.10.7
pyflakes==3.0.1
pymdown-extensions==9.11
pyOpenSSL==23.1.1
pyparsing==3.0.9
pyrsistent==0.19.3
PySocks==1.7.1
pytest==7.3.1
pytest-asyncio==0.21.0
pytest-benchmark==4.0.0
pytest-cov==4.0.0
pytest-integration==0.2.3
pytest-mock==3.10.0
pytest-recording==0.12.2
python-bidi==0.4.2
python-dateutil==2.8.2
python-dotenv==1.0.0
pytz==2023.3.post1
PyYAML==6.0
pyyaml_env_tag==0.1
readability-lxml==0.8.1
redis==4.5.4
regex==2023.5.5
requests==2.30.0
requests-oauthlib==1.3.1
rsa==4.9
SciPy==1.10.1
selenium==4.1.4
shellingham==1.5.0.post1
six==1.16.0
smart-open==6.3.0
smmap==5.0.0
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.4.1
spacy==3.5.2
spacy-legacy==3.0.12
spacy-loggers==1.0.4
srsly==2.4.6
thinc==8.1.10
tiktoken==0.3.3
tqdm==4.65.0
trio==0.22.0
trio-websocket==0.10.2
tweepy==4.14.0
typer==0.7.0
typing_extensions==4.5.0
tzdata==2023.3
uritemplate==4.1.1
urllib3==1.26.15
urllib3-secure-extra==0.1.0
vcrpy==4.2.1
virtualenv==20.23.0
wasabi==1.1.1
watchdog==3.0.0
webdriver-manager==3.8.6
websocket-client==1.5.1
Werkzeug==2.3.6
wrapt==1.15.0
wsproto==1.2.0
yarl==1.9.2

0 comments on commit 052f1f8

Please sign in to comment.