@@ -57,7 +57,7 @@ def split(total, num_people):
57
57
58
58
def do_hash (msg ):
59
59
m = hashlib .md5 ()
60
- m .update (msg )
60
+ m .update (msg . encode ( 'utf-8' ) )
61
61
return m .hexdigest ()
62
62
63
63
class Splitwise :
@@ -99,14 +99,18 @@ def get_client(self):
99
99
100
100
webbrowser .open_new (uri )
101
101
102
- proc = subprocess .Popen (['python' , 'server.py' ], stdout = subprocess .PIPE )
103
- stdout , stderr = proc .communicate ()
104
- if stderr :
105
- exit (stderr )
102
+ # proc = subprocess.Popen(['python', 'server.py'], stdout=subprocess.PIPE)
103
+ # stdout, stderr = proc.communicate()
104
+ # if stderr:
105
+ # exit(stderr)
106
+
107
+ verifier_input = input ('Copy the oauth verifier from the success page in the browser window : ' )
108
+
106
109
client = oauthlib .oauth1 .Client (self .ckey , client_secret = self .csecret ,
107
110
resource_owner_key = oauth_token ,
108
111
resource_owner_secret = oauth_secret ,
109
- verifier = stdout .strip ())
112
+ verifier = verifier_input )
113
+ #verifier=stdout.strip()) #bYpMPennhuz6bqMRZXd8
110
114
111
115
uri , headers , body = client .sign ("https://secure.splitwise.com/api/v3.0/get_access_token" ,
112
116
http_method = 'POST' )
@@ -117,7 +121,8 @@ def get_client(self):
117
121
client = oauthlib .oauth1 .Client (self .ckey , client_secret = self .csecret ,
118
122
resource_owner_key = oauth_token ,
119
123
resource_owner_secret = oauth_secret ,
120
- verifier = stdout .strip ())
124
+ verifier = verifier_input )
125
+ #verifier=stdout.strip())
121
126
with open ('oauth_client.pkl' , 'wb' ) as pkl :
122
127
pickle .dump (client , pkl )
123
128
self .client = client
@@ -160,24 +165,24 @@ def get_expenses(self, after_date="", limit=0, allow_deleted=True):
160
165
161
166
class CsvSettings ():
162
167
def __init__ (self , rows ):
163
- print "These are the first two rows of your csv"
164
- print ' \n ' .join ([str (t ) for t in rows [0 :2 ]])
165
- print ' Colnum numbers start at 0'
168
+ print ( "These are the first two rows of your csv" )
169
+ print ( " \n " .join ([str (t ) for t in rows [0 :2 ]]) )
170
+ print ( " Colnum numbers start at 0" )
166
171
self .date_col = input ("Which column has the date?" )
167
172
self .amount_col = input ("Which column has the amount?" )
168
173
self .desc_col = input ("Which column has the description?" )
169
- self .has_title_row = raw_input ("Does first row have titles? [Y/n]" ).lower () != 'n'
174
+ self .has_title_row = input ("Does first row have titles? [Y/n]" ).lower () != 'n'
170
175
self .newest_transaction = ''
171
176
while True :
172
177
try :
173
- self .local_currency = raw_input ("What currency were these transactions made in?" ).upper ()
178
+ self .local_currency = input ("What currency were these transactions made in?" ).upper ()
174
179
test = Money ("1.00" , self .local_currency ) #pylint: disable=W0612
175
180
except ValueError as err :
176
- print err
177
- print "Try again..."
181
+ print ( err )
182
+ print ( "Try again..." )
178
183
else :
179
184
break
180
- self .remember = raw_input ("Remember these settings? [Y/n]" ).lower () != 'n'
185
+ self .remember = input ("Remember these settings? [Y/n]" ).lower () != 'n'
181
186
182
187
def __del__ (self ):
183
188
if self .remember :
@@ -198,7 +203,7 @@ def __init__(self, options, args, api):
198
203
self .api = api
199
204
self .options = options
200
205
self .args = args
201
- with open (csv_file , 'rb ' ) as csvfile :
206
+ with open (csv_file , 'r ' ) as csvfile :
202
207
reader = csv .reader (csvfile )
203
208
self .rows = [x for x in reader ]
204
209
@@ -224,15 +229,17 @@ def make_transactions(self):
224
229
**change csvDateFormat to the format in your csv if necessary**
225
230
Further reading on date formats: https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
226
231
"""
227
- csvDateFormat = "%m/%d/%y"
232
+ csvDateFormat = "%m/%d/%Y"
228
233
self .transactions = []
229
234
for r in self .rows :
230
- if not self .options .try_all and do_hash (str (r )) == self .csv .newest_transaction :
231
- break
232
- if float (r [self .csv .amount_col ]) < 0 :
233
- self .transactions .append ({"date" : datetime .strftime (datetime .strptime (r [self .csv .date_col ], csvDateFormat ), "%Y-%m-%dT%H:%M:%SZ" ),
234
- "amount" : - 1 * Money (r [self .csv .amount_col ], self .csv .local_currency ),
235
- "desc" : re .sub ('\s+' ,' ' , r [self .csv .desc_col ])}
235
+ # if not self.options.try_all and do_hash(str(r)) == self.csv.newest_transaction:
236
+ # break
237
+ if float (r [int (self .csv .amount_col )]) > 0 :
238
+ self .transactions .append ({
239
+ "date" : datetime .strptime (r [int (self .csv .date_col )], csvDateFormat ).strftime ("%Y-%m-%dT%H:%M:%SZ" ),
240
+ "amount" : Money (r [int (self .csv .amount_col )], self .csv .local_currency ),
241
+ "desc" : re .sub (r'\s+' , ' ' , r [int (self .csv .desc_col )])
242
+ }
236
243
)
237
244
238
245
def get_group (self , name ):
@@ -269,19 +276,19 @@ def ask_for_splits(self):
269
276
add it to tee list of transactions to upload to Splitwise. Gets final
270
277
confirmation before returning.
271
278
"""
272
- print "Found {0} transactions" .format (len (self .transactions ))
279
+ print ( "Found {0} transactions" .format (len (self .transactions ) ))
273
280
i = 0
274
281
for t in self .transactions :
275
- if self .options .yes or raw_input ("%d: %s at %s $%s. Split? [y/N]" % (i , t ['date' ], t ['desc' ], t ['amount' ])).lower () == 'y' :
282
+ if self .options .yes or input ("%d: %s at %s $%s. Split? [y/N]" % (i , t ['date' ], t ['desc' ], t ['amount' ])).lower () == 'y' :
276
283
self .splits .append (t )
277
284
278
- print "-" * 40
279
- print "Your Chosen Splits"
280
- print "-" * 40
281
- print tabulate ( self .splits , headers = {"date" :"Date" , "amount" :"Amount" , "desc" :"Description" } )
285
+ print ( "-" * 40 )
286
+ print ( "Your Chosen Splits" )
287
+ print ( "-" * 40 )
288
+ print ( tabulate ( self .splits , headers = {"date" :"Date" , "amount" :"Amount" , "desc" :"Description" } ) )
282
289
283
290
# Kill program if user doesn't want to submit splits
284
- assert self .options .yes or raw_input ( "Confirm submission? [y/N]" ).lower () == 'y' , "User canceled submission"
291
+ assert self .options .yes or input ( "Confirm submission? [y/N]" ).lower () == 'y' , "User canceled submission"
285
292
286
293
def __getitem__ (self , index ):
287
294
"""
@@ -309,7 +316,7 @@ def __getitem__(self, index):
309
316
params ['users__%s__paid_share' % (i + 1 )] = 0
310
317
params ['users__%s__owed_share' % (i + 1 )] = (base + one_cent ).amount if extra .amount > 0 else base .amount
311
318
extra -= one_cent
312
- paramsStr = urllib .urlencode (params )
319
+ paramsStr = urllib .parse . urlencode (params )
313
320
return "https://secure.splitwise.com/api/v3.0/create_expense?%s" % (paramsStr )
314
321
315
322
@@ -326,14 +333,15 @@ def main():
326
333
logger .setLevel (log_levels [options .verbosity ])
327
334
splitwise = Splitwise (options .api_client )
328
335
split_gen = SplitGenerator (options , args , splitwise )
329
- print "Uploading splits"
336
+ print ( "Uploading splits" )
330
337
for uri in split_gen :
331
338
if options .dryrun :
332
- print uri
339
+ print ( uri )
333
340
continue
334
341
splitwise .post_expense (uri )
335
342
sys .stdout .write ("\n " )
336
343
sys .stdout .flush ()
337
344
345
+
338
346
if __name__ == "__main__" :
339
347
main ()
0 commit comments