[Update: The Atom draft is finished.]
Mr. Darcy has proposed marriage to me!
He is the last man on earth I would ever desire to marry.
Whatever shall I do?
410.10
ICD9
2004
en
ISO-639-1
410.10
ICD9
2004
136.9
ICD9_Broader
084.6
ICD9
S15814
HL7
C38305
FDA
C38305
FDA
C38288
FDA
21
HL7
C38305
FDA
C38305
FDA
410.10
ICD9
2004
21
HL7
C38288
FDA
136.9
ICD9_Broader
084.6
ICD9
S15814
HL7
testcomment |
5PreIj6z6ldIGL1V4+1C36dQFHNCQHJvW52GXc...
/E/wDit8YXPCxx126zTq2ilQ3IcW54NJYyNjiZ...
%s
\n' % numberToBase64(self.p) s += indent+'\t%s\n' % numberToBase64(self.q) s += indent+'\t
gdata.analytics.client
module for more details on usage.
main: The main method of this example.
GetAnalyticsClient: Returns an authorized AnalyticsClient object.
Class ManagementFeedDemo: Prints all the import Account Feed data.
"""
__author__ = 'api.nickm@google.com (Nick Mihailovski)'
import gdata.analytics.client
import gdata.sample_util
ACCOUNT_ID = '~all'
WEB_PROPERTY_ID = '~all'
PROFILE_ID = '~all'
def main():
"""Main example script. Un-comment each method to print the feed."""
demo = ManagementFeedDemo(GetAnalyticsClient())
demo.PrintAccountFeed()
# demo.PrintWebPropertyFeed()
# demo.PrintProfileFeed()
# demo.PrintGoalFeed()
# demo.PrintSegmentFeed()
def GetAnalyticsClient():
"""Returns an authorized GoogleAnalayticsClient object.
Uses the Google Data python samples wrapper to prompt the user for
credentials then tries to authorize the client object with the
Google Analytics API.
Returns:
An authorized GoogleAnalyticsClient object.
"""
SOURCE_APP_NAME = 'Analytics-ManagementAPI-Demo-v1'
my_client = gdata.analytics.client.AnalyticsClient(source=SOURCE_APP_NAME)
try:
gdata.sample_util.authorize_client(
my_client,
service=my_client.auth_service,
source=SOURCE_APP_NAME,
scopes=['https://www.google.com/analytics/feeds/'])
except gdata.client.BadAuthentication:
exit('Invalid user credentials given.')
except gdata.client.Error:
exit('Login Error')
return my_client
class ManagementFeedDemo(object):
"""The main demo for the management feed.
Attributes:
my_client: gdata.analytics.client The AnalyticsClient object for this demo.
"""
def __init__(self, my_client):
"""Initializes the ManagementFeedDemo class.
Args:
my_client: gdata.analytics.client An authorized GoogleAnalyticsClient
object.
"""
self.my_client = my_client
def PrintAccountFeed(self):
"""Requests and prints the important data in the Account Feed.
Note:
AccountQuery is used for the ManagementAPI.
AccountFeedQuery is used for the Data Export API.
"""
account_query = gdata.analytics.client.AccountQuery()
results = self.my_client.GetManagementFeed(account_query)
print '-------- Account Feed Data --------'
if not results.entry:
print 'no entries found'
else:
for entry in results.entry:
print 'Account Name = ' + entry.GetProperty('ga:accountName').value
print 'Account ID = ' + entry.GetProperty('ga:accountId').value
print 'Child Feed Link = ' + entry.GetChildLink('analytics#webproperties').href
print
def PrintWebPropertyFeed(self):
"""Requests and prints the important data in the Web Property Feed."""
web_property_query = gdata.analytics.client.WebPropertyQuery(
acct_id=ACCOUNT_ID)
results = self.my_client.GetManagementFeed(web_property_query)
print '-------- Web Property Feed Data --------'
if not results.entry:
print 'no entries found'
else:
for entry in results.entry:
print 'Account ID = ' + entry.GetProperty('ga:accountId').value
print 'Web Property ID = ' + entry.GetProperty('ga:webPropertyId').value
print 'Child Feed Link = ' + entry.GetChildLink('analytics#profiles').href
print
def PrintProfileFeed(self):
"""Requests and prints the important data in the Profile Feed.
Note:
TableId has a different namespace (dxp:) than all the
other properties (ga:).
"""
profile_query = gdata.analytics.client.ProfileQuery(
acct_id=ACCOUNT_ID, web_prop_id=WEB_PROPERTY_ID)
results = self.my_client.GetManagementFeed(profile_query)
print '-------- Profile Feed Data --------'
if not results.entry:
print 'no entries found'
else:
for entry in results.entry:
print 'Account ID = ' + entry.GetProperty('ga:accountId').value
print 'Web Property ID = ' + entry.GetProperty('ga:webPropertyId').value
print 'Profile ID = ' + entry.GetProperty('ga:profileId').value
print 'Currency = ' + entry.GetProperty('ga:currency').value
print 'Timezone = ' + entry.GetProperty('ga:timezone').value
print 'TableId = ' + entry.GetProperty('dxp:tableId').value
print 'Child Feed Link = ' + entry.GetChildLink('analytics#goals').href
print
def PrintGoalFeed(self):
"""Requests and prints the important data in the Goal Feed.
Note:
There are two types of goals, destination and engagement which need to
be handled differently.
"""
goal_query = gdata.analytics.client.GoalQuery(
acct_id=ACCOUNT_ID, web_prop_id=WEB_PROPERTY_ID, profile_id=PROFILE_ID)
results = self.my_client.GetManagementFeed(goal_query)
print '-------- Goal Feed Data --------'
if not results.entry:
print 'no entries found'
else:
for entry in results.entry:
print 'Goal Number = ' + entry.goal.number
print 'Goal Name = ' + entry.goal.name
print 'Goal Value = ' + entry.goal.value
print 'Goal Active = ' + entry.goal.active
if entry.goal.destination:
self.PrintDestinationGoal(entry.goal.destination)
elif entry.goal.engagement:
self.PrintEngagementGoal(entry.goal.engagement)
def PrintDestinationGoal(self, destination):
"""Prints the important information for destination goals including all
the configured steps if they exist.
Args:
destination: gdata.data.Destination The destination goal configuration.
"""
print '\t----- Destination Goal -----'
print '\tExpression = ' + destination.expression
print '\tMatch Type = ' + destination.match_type
print '\tStep 1 Required = ' + destination.step1_required
print '\tCase Sensitive = ' + destination.case_sensitive
if destination.step:
print '\t\t----- Destination Goal Steps -----'
for step in destination.step:
print '\t\tStep Number = ' + step.number
print '\t\tStep Name = ' + step.name
print '\t\tStep Path = ' + step.path
print
def PrintEngagementGoal(self, engagement):
"""Prints the important information for engagement goals.
Args:
engagement: gdata.data.Engagement The engagement goal configuration.
"""
print '\t----- Engagement Goal -----'
print '\tGoal Type = ' + engagement.type
print '\tGoal Engagement = ' + engagement.comparison
print '\tGoal Threshold = ' + engagement.threshold_value
print
def PrintSegmentFeed(self):
"""Requests and prints the important data in the Profile Feed."""
adv_seg_query = gdata.analytics.client.AdvSegQuery()
results = self.my_client.GetManagementFeed(adv_seg_query)
print '-------- Advanced Segment Feed Data --------'
if not results.entry:
print 'no entries found'
else:
for entry in results.entry:
print 'Segment ID = ' + entry.segment.id
print 'Segment Name = ' + entry.segment.name
print 'Segment Definition = ' + entry.segment.definition.text
print
if __name__ == '__main__':
main()
python-gdata-2.0.18+dfsg.orig/samples/analytics/account_feed_demo.py 0000755 0000000 0000000 00000015070 12156622362 024220 0 ustar root root #!/usr/bin/python
#
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Sample Google Analytics Data Export API Account Feed application.
This sample demonstrates how to retrieve the important data from the Google
Analytics Data Export API Account feed using the Python Client library. This
requires a Google Analytics username and password and uses the Client Login
authorization routine.
Class AccountFeedDemo: Prints all the import Account Feed data.
"""
__author__ = 'api.nickm@google.com (Nick Mihailovski)'
import gdata.analytics.client
import gdata.sample_util
def main():
"""Main fucntion for the sample."""
demo = AccountFeedDemo()
demo.PrintFeedDetails()
demo.PrintAdvancedSegments()
demo.PrintCustomVarForOneEntry()
demo.PrintGoalsForOneEntry()
demo.PrintAccountEntries()
class AccountFeedDemo(object):
"""Prints the Google Analytics account feed
Attributes:
account_feed: Google Analytics AccountList returned form the API.
"""
def __init__(self):
"""Inits AccountFeedDemo."""
SOURCE_APP_NAME = 'Google-accountFeedDemoPython-v1'
my_client = gdata.analytics.client.AnalyticsClient(source=SOURCE_APP_NAME)
try:
gdata.sample_util.authorize_client(
my_client,
service=my_client.auth_service,
source=SOURCE_APP_NAME,
scopes=['https://www.google.com/analytics/feeds/'])
except gdata.client.BadAuthentication:
exit('Invalid user credentials given.')
except gdata.client.Error:
exit('Login Error')
account_query = gdata.analytics.client.AccountFeedQuery()
self.feed = my_client.GetAccountFeed(account_query)
def PrintFeedDetails(self):
"""Prints important Analytics related data found at the top of the feed."""
print '-------- Important Feed Data --------'
print 'Feed Title = ' + self.feed.title.text
print 'Feed Id = ' + self.feed.id.text
print 'Total Results Found = ' + self.feed.total_results.text
print 'Start Index = ' + self.feed.start_index.text
print 'Results Returned = ' + self.feed.items_per_page.text
def PrintAdvancedSegments(self):
"""Prints the advanced segments for this user."""
print '-------- Advances Segments --------'
if not self.feed.segment:
print 'No advanced segments found'
else:
for segment in self.feed.segment:
print 'Segment Name = ' + segment.name
print 'Segment Id = ' + segment.id
print 'Segment Definition = ' + segment.definition.text
def PrintCustomVarForOneEntry(self):
"""Prints custom variable information for the first profile that has
custom variable configured."""
print '-------- Custom Variables --------'
if not self.feed.entry:
print 'No entries found'
else:
for entry in self.feed.entry:
if entry.custom_variable:
for custom_variable in entry.custom_variable:
print 'Custom Variable Index = ' + custom_variable.index
print 'Custom Variable Name = ' + custom_variable.name
print 'Custom Variable Scope = ' + custom_variable.scope
return
print 'No custom variables defined for this user'
def PrintGoalsForOneEntry(self):
"""Prints All the goal information for one profile."""
print '-------- Goal Configuration --------'
if not self.feed.entry:
print 'No entries found'
else:
for entry in self.feed.entry:
if entry.goal:
for goal in entry.goal:
print 'Goal Number = ' + goal.number
print 'Goal Name = ' + goal.name
print 'Goal Value = ' + goal.value
print 'Goal Active = ' + goal.active
if goal.destination:
self.PrintDestinationGoal(goal.destination)
elif goal.engagement:
self.PrintEngagementGoal(goal.engagement)
return
def PrintDestinationGoal(self, destination):
"""Prints the important information for destination goals including all
the configured steps if they exist.
Args:
destination: gdata.data.Destination The destination goal configuration.
"""
print '----- Destination Goal -----'
print 'Expression = ' + destination.expression
print 'Match Type = ' + destination.match_type
print 'Step 1 Required = ' + destination.step1_required
print 'Case Sensitive = ' + destination.case_sensitive
# Print goal steps.
if destination.step:
print '----- Destination Goal Steps -----'
for step in destination.step:
print 'Step Number = ' + step.number
print 'Step Name = ' + step.name
print 'Step Path = ' + step.path
def PrintEngagementGoal(self, engagement):
"""Prints the important information for engagement goals.
Args:
engagement: gdata.data.Engagement The engagement goal configuration.
"""
print '----- Engagement Goal -----'
print 'Goal Type = ' + engagement.type
print 'Goal Engagement = ' + engagement.comparison
print 'Goal Threshold = ' + engagement.threshold_value
def PrintAccountEntries(self):
"""Prints important Analytics data found in each account entry"""
print '-------- First 1000 Profiles in Account Feed --------'
if not self.feed.entry:
print 'No entries found'
else:
for entry in self.feed.entry:
print 'Web Property ID = ' + entry.GetProperty('ga:webPropertyId').value
print 'Account Name = ' + entry.GetProperty('ga:accountName').value
print 'Account Id = ' + entry.GetProperty('ga:accountId').value
print 'Profile Name = ' + entry.title.text
print 'Profile ID = ' + entry.GetProperty('ga:profileId').value
print 'Table ID = ' + entry.table_id.text
print 'Currency = ' + entry.GetProperty('ga:currency').value
print 'TimeZone = ' + entry.GetProperty('ga:timezone').value
if entry.custom_variable:
print 'This profile has custom variables'
if entry.goal:
print 'This profile has goals'
if __name__ == '__main__':
main()
python-gdata-2.0.18+dfsg.orig/samples/analytics/data_feed_demo.py 0000755 0000000 0000000 00000014146 12156622362 023500 0 ustar root root #!/usr/bin/python
#
# Copyright 2009 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Sample Google Analytics Data Export API Data Feed application.
This sample demonstrates how to make requests and retrieve the important
information from the Google Analytics Data Export API Data Feed. This
sample requires a Google Analytics username and password and uses the
Client Login authorization routine.
Class DataFeedDemo: Prints all the important Data Feed informantion.
"""
__author__ = 'api.nickm@google.com (Nick Mihailovski)'
import gdata.analytics.client
import gdata.sample_util
def main():
"""Main function for the sample."""
demo = DataFeedDemo()
demo.PrintFeedDetails()
demo.PrintDataSources()
demo.PrintFeedAggregates()
demo.PrintSegmentInfo()
demo.PrintOneEntry()
demo.PrintFeedTable()
class DataFeedDemo(object):
"""Gets data from the Data Feed.
Attributes:
data_feed: Google Analytics AccountList returned form the API.
"""
def __init__(self):
"""Inits DataFeedDemo."""
SOURCE_APP_NAME = 'Google-dataFeedDemoPython-v2'
my_client = gdata.analytics.client.AnalyticsClient(source=SOURCE_APP_NAME)
try:
gdata.sample_util.authorize_client(
my_client,
service=my_client.auth_service,
source=SOURCE_APP_NAME,
scopes=['https://www.google.com/analytics/feeds/'])
except gdata.client.BadAuthentication:
exit('Invalid user credentials given.')
except gdata.client.Error:
exit('Login Error')
table_id = gdata.sample_util.get_param(
name='table_id',
prompt='Please enter your Google Analytics Table id (format ga:xxxx)')
# DataFeedQuery simplifies constructing API queries and uri encodes params.
data_query = gdata.analytics.client.DataFeedQuery({
'ids': table_id,
'start-date': '2008-10-01',
'end-date': '2008-10-30',
'dimensions': 'ga:source,ga:medium',
'metrics': 'ga:visits',
'sort': '-ga:visits',
'filters': 'ga:medium==referral',
'max-results': '50'})
self.feed = my_client.GetDataFeed(data_query)
def PrintFeedDetails(self):
"""Prints important Analytics related data found at the top of the feed."""
print '\n-------- Feed Data --------'
print 'Feed Title = ' + self.feed.title.text
print 'Feed Id = ' + self.feed.id.text
print 'Total Results Found = ' + self.feed.total_results.text
print 'Start Index = ' + self.feed.start_index.text
print 'Results Returned = ' + self.feed.items_per_page.text
print 'Start Date = ' + self.feed.start_date.text
print 'End Date = ' + self.feed.end_date.text
print 'Has Sampled Data = ' + str(self.feed.HasSampledData())
def PrintDataSources(self):
"""Prints data found in the data source elements.
This data has information about the Google Analytics account the referenced
table ID belongs to. Note there is currently exactly one data source in
the data feed.
"""
data_source = self.feed.data_source[0]
print '\n-------- Data Source Data --------'
print 'Table ID = ' + data_source.table_id.text
print 'Table Name = ' + data_source.table_name.text
print 'Web Property Id = ' + data_source.GetProperty('ga:webPropertyId').value
print 'Profile Id = ' + data_source.GetProperty('ga:profileId').value
print 'Account Name = ' + data_source.GetProperty('ga:accountName').value
def PrintFeedAggregates(self):
"""Prints data found in the aggregates elements.
This contains the sum of all the metrics defined in the query across.
This sum spans all the rows matched in the feed.total_results property
and not just the rows returned by the response.
"""
aggregates = self.feed.aggregates
print '\n-------- Metric Aggregates --------'
for met in aggregates.metric:
print ''
print 'Metric Name = ' + met.name
print 'Metric Value = ' + met.value
print 'Metric Type = ' + met.type
print 'Metric CI = ' + met.confidence_interval
def PrintSegmentInfo(self):
"""Prints segment information if the query has advanced segments
defined."""
print '-------- Advanced Segments Information --------'
if self.feed.segment:
if segment.name:
print 'Segment Name = ' + str(segment.name)
if segment.id:
print 'Segment Id = ' + str(segment.id)
print 'Segment Definition = ' + segment.definition.text
else:
print 'No segments defined'
def PrintOneEntry(self):
"""Prints all the important Google Analytics data found in an entry"""
print '\n-------- One Entry --------'
if len(self.feed.entry) == 0:
print 'No entries found'
return
entry = self.feed.entry[0]
print 'ID = ' + entry.id.text
for dim in entry.dimension:
print 'Dimension Name = ' + dim.name
print 'Dimension Value = ' + dim.value
for met in entry.metric:
print 'Metric Name = ' + met.name
print 'Metric Value = ' + met.value
print 'Metric Type = ' + met.type
print 'Metric CI = ' + met.confidence_interval
def PrintFeedTable(self):
"""Prints all the entries as a table."""
print '\n-------- All Entries In a Table --------'
for entry in self.feed.entry:
for dim in entry.dimension:
print ('Dimension Name = %s \t Dimension Value = %s'
% (dim.name, dim.value))
for met in entry.metric:
print ('Metric Name = %s \t Metric Value = %s'
% (met.name, met.value))
print '---'
if __name__ == '__main__':
main()
python-gdata-2.0.18+dfsg.orig/samples/webmastertools/ 0000755 0000000 0000000 00000000000 12156625015 021276 5 ustar root root python-gdata-2.0.18+dfsg.orig/samples/webmastertools/SitemapsFeedSummary.py 0000755 0000000 0000000 00000003526 12156622362 025612 0 ustar root root #!/usr/bin/python
#
# Copyright (C) 2008 Yu-Jie Lin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import gdata.webmastertools.service
import gdata.service
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import atom
import getpass
username = ''
password = ''
site_uri = ''
username = raw_input('Please enter your username: ')
password = getpass.getpass()
site_uri = raw_input('Please enter your site url: ')
client = gdata.webmastertools.service.GWebmasterToolsService(
email=username,
password=password, source='PythonWebmasterToolsSample-1')
print 'Logging in'
client.ProgrammaticLogin()
print 'Retrieving Sitemaps feed'
feed = client.GetSitemapsFeed(site_uri)
# Format the feed
print
print 'You have %d sitemap(s), last updated at %s' % (
len(feed.entry), feed.updated.text)
print
print '='*80
def safeElementText(element):
if hasattr(element, 'text'):
return element.text
return ''
# Format each site
for entry in feed.entry:
print entry.title.text.replace('http://', '')[:80]
print " Last Updated : %29s Status: %10s" % (
entry.updated.text[:29], entry.sitemap_status.text[:10])
print " Last Downloaded: %29s URL Count: %10s" % (
safeElementText(entry.sitemap_last_downloaded)[:29],
safeElementText(entry.sitemap_url_count)[:10])
print
python-gdata-2.0.18+dfsg.orig/samples/webmastertools/SitesFeedSummary.py 0000755 0000000 0000000 00000003667 12156622362 025122 0 ustar root root #!/usr/bin/python
#
# Copyright (C) 2008 Yu-Jie Lin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import gdata.webmastertools.service
import gdata.service
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import atom
import getpass
username = ''
password = ''
username = raw_input('Please enter your username: ')
password = getpass.getpass()
client = gdata.webmastertools.service.GWebmasterToolsService(
email=username,
password=password, source='PythonWebmasterToolsSample-1')
print 'Logging in'
client.ProgrammaticLogin()
print 'Retrieving Sites feed'
feed = client.GetSitesFeed()
# Format the feed
print
print 'You have %d site(s), last updated at %s' % (
len(feed.entry), feed.updated.text)
print
print "%-25s %25s %25s" % ('Site', 'Last Updated', 'Last Crawled')
print '='*80
def safeElementText(element):
if hasattr(element, 'text'):
return element.text
return ''
# Format each site
for entry in feed.entry:
print "%-25s %25s %25s" % (
entry.title.text.replace('http://', '')[:25], entry.updated.text[:25],
safeElementText(entry.crawled)[:25])
print " Preferred: %-23s Indexed: %5s GeoLoc: %10s" % (
safeElementText(entry.preferred_domain)[:30], entry.indexed.text[:5],
safeElementText(entry.geolocation)[:10])
print " Crawl rate: %-10s Verified: %5s" % (
safeElementText(entry.crawl_rate)[:10], entry.verified.text[:5])
print
python-gdata-2.0.18+dfsg.orig/samples/webmastertools/AddDeleteExampleDotCom.py 0000755 0000000 0000000 00000006346 12156622362 026123 0 ustar root root #!/usr/bin/python
#
# Copyright (C) 2008 Yu-Jie Lin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import urllib
import gdata.webmastertools.service
import gdata.service
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import atom
import getpass
username = ''
password = ''
username = raw_input('Please enter your username: ')
password = getpass.getpass()
client = gdata.webmastertools.service.GWebmasterToolsService(
email=username,
password=password, source='PythonWebmasterToolsSample-1')
EXAMPLE_SITE = 'http://www.example.com/'
EXAMPLE_SITEMAP = 'http://www.example.com/sitemap-index.xml'
def safeElementText(element):
if hasattr(element, 'text'):
return element.text
return ''
print 'Logging in'
client.ProgrammaticLogin()
print
print 'Adding site: %s' % EXAMPLE_SITE
entry = client.AddSite(EXAMPLE_SITE)
print
print "%-25s %25s %25s" % ('Site', 'Last Updated', 'Last Crawled')
print '='*80
print "%-25s %25s %25s" % (
entry.title.text.replace('http://', '')[:25], entry.updated.text[:25],
safeElementText(entry.crawled)[:25])
print " Preferred: %-23s Indexed: %5s GeoLoc: %10s" % (
safeElementText(entry.preferred_domain)[:30], entry.indexed.text[:5],
safeElementText(entry.geolocation)[:10])
print " Crawl rate: %-10s Verified: %5s" % (
safeElementText(entry.crawl_rate)[:10], entry.verified.text[:5])
# Verifying a site. This sample won't do this since we don't own example.com
#client.VerifySite(EXAMPLE_SITE, 'htmlpage')
# The following needs the ownership of the site
#client.UpdateGeoLocation(EXAMPLE_SITE, 'US')
#client.UpdateCrawlRate(EXAMPLE_SITE, 'normal')
#client.UpdatePreferredDomain(EXAMPLE_SITE, 'preferwww')
#client.UpdateEnhancedImageSearch(EXAMPLE_SITE, 'true')
print
print 'Adding sitemap: %s' % EXAMPLE_SITEMAP
entry = client.AddSitemap(EXAMPLE_SITE, EXAMPLE_SITEMAP)
print entry.title.text.replace('http://', '')[:80]
print " Last Updated : %29s Status: %10s" % (
entry.updated.text[:29], entry.sitemap_status.text[:10])
print " Last Downloaded: %29s URL Count: %10s" % (
safeElementText(entry.sitemap_last_downloaded)[:29],
safeElementText(entry.sitemap_url_count)[:10])
# Add a mobile sitemap
#entry = client.AddMobileSitemap(EXAMPLE_SITE, 'http://.../sitemap-mobile-example.xml', 'XHTML')
# Add a news sitemap, your site must be included in Google News.
# See also http://google.com/support/webmasters/bin/answer.py?answer=42738
#entry = client.AddNewsSitemap(EXAMPLE_SITE, 'http://.../sitemap-news-example.xml', 'Label')
print
print 'Deleting sitemap: %s' % EXAMPLE_SITEMAP
client.DeleteSitemap(EXAMPLE_SITE, EXAMPLE_SITEMAP)
print
print 'Deleting site: %s' % EXAMPLE_SITE
client.DeleteSite(EXAMPLE_SITE)
print
python-gdata-2.0.18+dfsg.orig/samples/finance/ 0000755 0000000 0000000 00000000000 12156625015 017627 5 ustar root root python-gdata-2.0.18+dfsg.orig/samples/finance/test_finance.py 0000755 0000000 0000000 00000025041 12156622362 022652 0 ustar root root #!/usr/bin/python
#
# Copyright (C) 2009 Tan Swee Heng
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = 'thesweeheng@gmail.com'
from gdata.finance.service import \
FinanceService, PortfolioQuery, PositionQuery
from gdata.finance import \
PortfolioEntry, PortfolioData, TransactionEntry, TransactionData, \
Price, Commission, Money
import datetime
import sys
def PrintReturns(pfx, d):
"""Print returns."""
print pfx, '%1.5f(1w) %1.5f(4w) %1.5f(3m) %1.5f(YTD)' % tuple(
float(i) for i in (d.return1w, d.return4w, d.return3m, d.returnYTD))
pfx = ' ' * len(pfx)
print pfx, '%1.5f(1y) %1.5f(3y) %1.5f(5y) %1.5f(overall)' % tuple(
float(i) for i in (d.return1y, d.return3y, d.return5y, d.return_overall))
PrRtn = PrintReturns
def PrintTransactions(transactions):
"""Print transactions."""
print " Transactions:"
fmt = ' %4s %-23s %-10s %6s %-11s %-11s'
print fmt % ('ID','Date','Type','Shares','Price','Commission')
for txn in transactions:
d = txn.transaction_data
print fmt % (txn.transaction_id, d.date or '----', d.type,
d.shares, d.price.money[0], d.commission.money[0])
if d.notes:
print " Notes:", d.notes
print
def PrintPosition(pos, with_returns=False):
"""Print single position."""
print ' Position :', pos.position_title
print ' Ticker ID :', pos.ticker_id
print ' Symbol :', pos.symbol
print ' Last updated :', pos.updated.text
d = pos.position_data
print ' Shares :', d.shares
if with_returns:
print ' Gain % :', d.gain_percentage
PrRtn(' Returns :', d)
print ' Cost basis :', d.cost_basis
print ' Days gain :', d.days_gain
print ' Gain :', d.gain
print ' Market value :', d.market_value
print
if pos.transactions:
print "