<s> """<STR_LIT>""" <EOL> import argparse <EOL> import csv <EOL> import os . path <EOL> import pickle <EOL> import sys <EOL> import webbrowser <EOL> xero_config = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> from xero import Xero <EOL> from xero . auth import PublicCredentials <EOL> argp = argparse . ArgumentParser ( description = __doc__ ) <EOL> argp . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT:->' , help = '<STR_LIT>' ) <EOL> argp . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> args = argp . parse_args ( ) <EOL> if os . path . isfile ( args . credentials_file ) : <EOL> with open ( args . credentials_file , '<STR_LIT:r>' ) as credentials_fh : <EOL> credentials_state = pickle . loads ( credentials_fh . read ( ) ) <EOL> credentials = PublicCredentials ( ** credentials_state ) <EOL> else : <EOL> credentials = PublicCredentials ( xero_config [ '<STR_LIT>' ] , xero_config [ '<STR_LIT>' ] ) <EOL> print credentials . url <EOL> webbrowser . open ( credentials . url ) <EOL> verifier = raw_input ( '<STR_LIT>' ) <EOL> credentials . verify ( verifier ) <EOL> with open ( args . credentials_file , '<STR_LIT:w>' ) as credentials_fh : <EOL> pickle . dump ( credentials . state , credentials_fh ) <EOL> xero = Xero ( credentials ) <EOL> userids = { } <EOL> users = xero . users . all ( ) <EOL> for user in users : <EOL> userids [ user [ '<STR_LIT>' ] ] = user [ '<STR_LIT>' ] <EOL> if args . input_file == '<STR_LIT:->' : <EOL> in_fh = sys . stdin <EOL> else : <EOL> in_fh = open ( args . input_file , '<STR_LIT:r>' ) <EOL> reader = csv . DictReader ( in_fh , delimiter = '<STR_LIT:U+002C>' ) <EOL> receipts = [ ] <EOL> for i in reader : <EOL> user_email = i [ '<STR_LIT>' ] <EOL> if user_email not in userids : <EOL> print "<STR_LIT>" % ( user_email , ) <EOL> continue <EOL> userid = userids [ i [ '<STR_LIT>' ] ] , <EOL> data = { <EOL> '<STR_LIT>' : i [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { '<STR_LIT:Name>' : i [ '<STR_LIT>' ] } , <EOL> '<STR_LIT>' : i [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ <EOL> { '<STR_LIT>' : i [ '<STR_LIT>' ] , '<STR_LIT>' : i [ '<STR_LIT>' ] , '<STR_LIT>' : i [ '<STR_LIT>' ] } , <EOL> ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : userids [ i [ '<STR_LIT>' ] ] } , <EOL> } <EOL> receipts . append ( data ) <EOL> if receipts : <EOL> results = xero . receipts . put ( receipts ) </s>
