Last active
August 29, 2015 14:04
-
-
Save paxswill/6bf55dfd78c460185b8b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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