-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_trial1.py
66 lines (51 loc) · 2.08 KB
/
app_trial1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#PRATHAMESH CHANDRAKANT CHAUDHARI
import configparser
# Importing database objects from config
config_obj = configparser.ConfigParser()
config_obj.read("config.py")
db_config = config_obj["splitwise"]
consumer_key = db_config["consumer_key"]
consumer_secret = db_config["consumer_secret"]
oauth_token = db_config["oauth_token"]
oauth_verifier = db_config["oauth_verifier"]
from flask import Flask, request, render_template, redirect, url_for
from splitwise import Splitwise
import pandas as pd
app = Flask(__name__)
# Set your redirect URI to the URL where Splitwise will redirect after authorization
redirect_uri = 'http://localhost:5000/auth_callback'
# Flask secret key for session
app.secret_key = 'abc'
# Splitwise object
sObj = Splitwise(consumer_key, consumer_secret)
@app.route('/')
def index():
# Step 1: Obtain the oauth_token
request_token = sObj.getRequestToken()
auth_url = sObj.getAuthorizeURL(request_token)
return redirect(auth_url)
@app.route('/auth_callback')
def auth_callback():
oauth_token = request.args.get('oauth_token')
oauth_token_secret = "https://secure.splitwise.com/oauth/access_token"
oauth_verifier = request.args.get('oauth_verifier')
access_token = sObj.getAccessToken(oauth_token, oauth_token_secret, oauth_verifier)
sObj.setAccessToken(access_token)
# # Fetch user's expenses
# expenses = sObj.getExpenses()
# # Convert expenses data to a Pandas DataFrame
# expenses_data = []
# for expense in expenses:
# expenses_data.append({
# 'Description': expense.description,
# 'Amount': expense.cost.amount,
# 'Currency': expense.cost.currency_code,
# 'Date': expense.date,
# 'Category': expense.category.name if expense.category else None
# })
# df = pd.DataFrame(expenses_data)
# # Save expenses to Excel sheet
# df.to_excel('user_expenses.xlsx', index=False)
return 'Expenses fetched and saved to Excel sheet.'
if __name__ == '__main__':
app.run(debug=True)