Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from evesrp.killmail import ZKillmail
import gdata.spreadsheets.client
from decimal import Decimal
# patch the spreadsheet's client to use the public feeds
gdata.spreadsheets.client.PRIVATE_WORKSHEETS_URL = \
gdata.spreadsheets.client.WORKSHEETS_URL
gdata.spreadsheets.client.WORKSHEETS_URL = ('https://spreadsheets.google.com/'
'feeds/worksheets/%s/public/full')
gdata.spreadsheets.client.PRIVATE_LISTS_URL = \
gdata.spreadsheets.client.LISTS_URL
gdata.spreadsheets.client.LISTS_URL = ('https://spreadsheets.google.com/feeds/'
'list/%s/%s/public/full')
class AutomagicPayout(ZKillmail):
# The spreadsheet's key
# (https://docs.google.com/spreadsheets/d/THE_PART_HERE/edit).
# Make sure the spreadsheet has been published (File->Publish to web...)
spreadsheet_key = 'THE_PART_HERE'
# The name of the worksheet with the payouts
worksheet_name = 'Payouts'
# The header for the hull column (always lowercase, the Google API
# lowercases it).
hull_key = 'hull'
# And the same for the payout column
payout_key = 'payout'
client = gdata.spreadsheets.client.SpreadsheetsClient()
@property
def value(self):
# Find the worksheet
sheets = self.client.get_worksheets(self.spreadsheet_key)
for sheet in sheets.entry:
if sheet.title.text == self.worksheet_name:
worksheet_id = sheet.get_worksheet_id()
break
else:
return Decimal('0')
# Read the worksheet's data
lists = self.client.get_list_feed(self.spreadsheet_key, worksheet_id,
query=gdata.spreadsheets.client.ListQuery(sq='{}={}'.format(
self.hull_key, self.ship)))
for entry in lists.entry:
return Decimal(entry.get_value(self.payout_key))
return Decimal('0')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment