docstring stringlengths 52 499 | function stringlengths 67 35.2k | __index_level_0__ int64 52.6k 1.16M |
|---|---|---|
Use this method to add contacts to your Telegram address book.
Args:
contacts (List of :obj:`InputPhoneContact <pyrogram.InputPhoneContact>`):
The contact list to be added
Returns:
On success, the added contacts are returned.
Raises:
:class:... | def add_contacts(
self,
contacts: List["pyrogram.InputPhoneContact"]
):
imported_contacts = self.send(
functions.contacts.ImportContacts(
contacts=contacts
)
)
return imported_contacts | 150,658 |
Use this method to turn off the Two-Step Verification security feature (Cloud Password) on your account.
Args:
password (``str``):
Your current password.
Returns:
True on success.
Raises:
:class:`RPCError <pyrogram.RPCError>` in case of a Te... | def remove_cloud_password(
self,
password: str
) -> bool:
r = self.send(functions.account.GetPassword())
if not r.has_password:
raise ValueError("There is no cloud password to remove")
self.send(
functions.account.UpdatePasswordSettings(
... | 150,679 |
Use this method to delete contacts from your Telegram address book.
Args:
ids (List of ``int``):
A list of unique identifiers for the target users.
Can be an ID (int), a username (string) or phone number (string).
Returns:
True on success.
... | def delete_contacts(
self,
ids: List[int]
):
contacts = []
for i in ids:
try:
input_user = self.resolve_peer(i)
except PeerIdInvalid:
continue
else:
if isinstance(input_user, types.InputPeer... | 150,684 |
Filter messages that match a given RegEx pattern.
Args:
pattern (``str``):
The RegEx pattern as string, it will be applied to the text of a message. When a pattern matches,
all the `Match Objects <https://docs.python.org/3/library/re.html#match-objects>`_
... | def regex(pattern, flags: int = 0):
def f(_, m):
m.matches = [i for i in _.p.finditer(m.text or m.caption or "")]
return bool(m.matches)
return create("Regex", f, p=re.compile(pattern, flags)) | 150,744 |
Initializer.
Args:
name: The name, e.g. 'Pattern'.
type_var: The type parameter, e.g. AnyStr, or the
specific type, e.g. str.
impl_type: The implementation type.
type_checker: Function that takes an impl_type instance.
and returns ... | def __init__(self, name, type_var, impl_type, type_checker):
assert isinstance(name, str), repr(name)
assert isinstance(impl_type, type), repr(impl_type)
assert not isinstance(impl_type, TypingMeta), repr(impl_type)
assert isinstance(type_var, (type, _TypingBase)), repr(type_var... | 150,785 |
Use this method to join a group chat or channel.
Args:
chat_id (``str``):
Unique identifier for the target chat in form of a *t.me/joinchat/* link or username of the target
channel/supergroup (in the format @username).
Returns:
On success, a :obj... | def join_chat(
self,
chat_id: str
):
match = self.INVITE_LINK_RE.match(chat_id)
if match:
chat = self.send(
functions.messages.ImportChatInvite(
hash=match.group(1)
)
)
if isinstance(cha... | 150,863 |
Use this method to delete your own profile photos.
Args:
id (``str`` | ``list``):
A single :obj:`Photo <pyrogram.Photo>` id as string or multiple ids as list of strings for deleting
more than one photos at once.
Returns:
True on success.
... | def delete_user_profile_photos(
self,
id: Union[str, List[str]]
) -> bool:
id = id if isinstance(id, list) else [id]
input_photos = []
for i in id:
s = unpack("<qq", b64decode(i + "=" * (-len(i) % 4), "-_"))
input_photos.append(
... | 150,876 |
Use this method to leave a group chat or channel.
Args:
chat_id (``int`` | ``str``):
Unique identifier for the target chat or username of the target channel/supergroup
(in the format @username).
delete (``bool``, *optional*):
Deletes the ... | def leave_chat(
self,
chat_id: Union[int, str],
delete: bool = False
):
peer = self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChannel):
return self.send(
functions.channels.LeaveChannel(
channel=self.res... | 150,884 |
Apply warping_function to some Input data
Parameters:
-----------
X : array_like, shape = (n_samples, n_features)
test_data: bool, optional
Default to False, should set to True when transforming test data
Returns
-------
X_warped : array_like, shape... | def f(self, X, test_data=False):
X_warped = X.copy()
if test_data:
X_normalized = (X - self.Xmin) / (self.Xmax - self.Xmin)
else:
X_normalized = self.X_normalized
for i_seq, i_fea in enumerate(self.warping_indices):
a, b = self.params[i_seq][... | 151,687 |
Get the log likelihood of a combined set of clusters, fitting the offsets
arguments:
inputs -- the 'X's in a list, one item per cluster
data -- the 'Y's in a list, one item per cluster
clust -- list of clusters to use
returns a tuple:
log likelihood and the offset | def get_log_likelihood_offset(inputs,data,clust):
#if we've only got one cluster, the model has an error, so we want to just
#use normal GPRegression.
if len(clust)==1:
return get_log_likelihood(inputs,data,clust)
S = data[0].shape[0] #number of time series
... | 151,870 |
Creates ExpandedTextAds that use ad customizations for specified AdGroups.
Args:
client: an AdWordsClient instance.
adgroup_ids: a list containing the AdGroup ids to add ExpandedTextAds to.
feed_name: the name of the feed used to apply customizations.
Raises:
GoogleAdsError: if no ExpandedTextAds ... | def CreateAdsWithCustomizations(client, adgroup_ids, feed_name):
# Get the AdGroupAdService
adgroup_ad_service = client.GetService('AdGroupAdService', 'v201809')
expanded_text_ad = {
'xsi_type': 'ExpandedTextAd',
'headlinePart1': 'Luxury Cruise to {=%s.Name}' % feed_name,
'headlinePart2': 'O... | 152,643 |
Creates a new AdCustomizerFeed.
Args:
client: an AdWordsClient instance.
feed_name: the name for the new AdCustomizerFeed.
Returns:
The new AdCustomizerFeed. | def CreateCustomizerFeed(client, feed_name):
# Get the AdCustomizerFeedService
ad_customizer_feed_service = client.GetService('AdCustomizerFeedService',
'v201809')
customizer_feed = {
'feedName': feed_name,
'feedAttributes': [
{'type': 'STR... | 152,644 |
Restricts the feed item to an ad group.
Args:
client: an AdWordsClient instance.
feed_item: The feed item.
adgroup_id: The ad group ID. | def RestrictFeedItemToAdGroup(client, feed_item, adgroup_id):
# Get the FeedItemTargetService
feed_item_target_service = client.GetService(
'FeedItemTargetService', 'v201809')
# Optional: Restrict the first feed item to only serve with ads for the
# specified ad group ID.
ad_group_target = {
'... | 152,645 |
Creates FeedItems for the specified AdGroups.
These FeedItems contain values to use in ad customizations for the AdGroups.
Args:
client: an AdWordsClient instance.
adgroup_ids: a list containing two AdGroup Ids.
ad_customizer_feed: the AdCustomizerFeed we're associating the FeedItems
with.
... | def CreateCustomizerFeedItems(client, adgroup_ids, ad_customizer_feed):
# Get the FeedItemService
feed_item_service = client.GetService('FeedItemService', 'v201809')
now = datetime.now()
mars_date = datetime(now.year, now.month, 1, 0, 0)
venus_date = datetime(now.year, now.month, 15, 0, 0)
time_format = ... | 152,646 |
Creates a FeedItemOperation.
The generated FeedItemOperation will create a FeedItem with the specified
values when sent to FeedItemService.mutate.
Args:
name: the value for the name attribute of the FeedItem.
price: the value for the price attribute of the FeedItem.
date: the value for the date attr... | def CreateFeedItemAddOperation(name, price, date, ad_customizer_feed):
feed_item = {
'feedId': ad_customizer_feed['feedId'],
'attributeValues': [
{
'feedAttributeId': ad_customizer_feed['feedAttributes'][0]['id'],
'stringValue': name
},
{
... | 152,647 |
Creates an AdWordsClient with information stored in a yaml string.
Args:
yaml_doc: The yaml string containing the cached AdWords data.
Returns:
An AdWordsClient initialized with the values cached in the string.
Raises:
A GoogleAdsValueError if the given yaml string does not contain the
... | def LoadFromString(cls, yaml_doc):
return cls(**googleads.common.LoadFromString(
yaml_doc, cls._YAML_KEY, cls._REQUIRED_INIT_VALUES,
cls._OPTIONAL_INIT_VALUES)) | 152,659 |
Creates an AdWordsClient with information stored in a yaml file.
Args:
[optional]
path: The path string to the file containing cached AdWords data.
Returns:
An AdWordsClient initialized with the values cached in the file.
Raises:
A GoogleAdsValueError if the given yaml file does n... | def LoadFromStorage(cls, path=None):
if path is None:
path = os.path.join(os.path.expanduser('~'), 'googleads.yaml')
return cls(**googleads.common.LoadFromStorage(
path, cls._YAML_KEY, cls._REQUIRED_INIT_VALUES,
cls._OPTIONAL_INIT_VALUES)) | 152,660 |
Returns the SOAP headers required for request authorization.
Args:
create_method: The SOAP library specific method used to instantiate SOAP
objects.
Returns:
A SOAP object containing the headers. | def GetSOAPHeaders(self, create_method):
header = create_method(self._SOAP_HEADER_CLASS % self._version)
header.clientCustomerId = self._adwords_client.client_customer_id
header.developerToken = self._adwords_client.developer_token
header.userAgent = ''.join([
self._adwords_client.user_agen... | 152,666 |
Pack the given object using AdWords-specific logic.
Args:
obj: an object to be packed for SOAP using AdWords-specific logic, if
applicable.
version: the version of the current API, e.g. 'v201809'
Returns:
The given object packed with AdWords-specific logic for SOAP, if
applic... | def Pack(cls, obj, version):
if isinstance(obj, ServiceQuery):
return str(obj)
return obj | 152,669 |
Initializes the IncrementalUpload.
Args:
request_builder: an AbstractUploadRequestBuilder instance.
upload_url: a string url provided by the BatchJobService.
current_content_length: an integer identifying the current content length
of data uploaded to the Batch Job.
is_last: a boole... | def __init__(self, request_builder, upload_url, current_content_length=0,
is_last=False):
self._request_builder = request_builder
if current_content_length < 0:
raise googleads.errors.GoogleAdsValueError(
'Current content length %s is < 0.' % current_content_length)
self.... | 152,671 |
Ensures that the URL used to upload operations is properly initialized.
Args:
upload_url: a string url.
current_content_length: an integer identifying the current content length
of data uploaded to the Batch Job.
Returns:
An initialized string URL, or the provided string URL if the U... | def _InitializeURL(self, upload_url, current_content_length):
# If initialization is not necessary, return the provided upload_url.
if current_content_length != 0:
return upload_url
headers = {
'Content-Type': 'application/xml',
'Content-Length': 0,
'x-goog-resumable': 's... | 152,672 |
Serialize the IncrementalUploadHelper and store in file-like object.
Args:
output: a file-like object where the status of the IncrementalUploadHelper
will be written.
Raises:
GoogleAdsError: If a YAMLError occurs while writing to the file. | def Dump(self, output):
data = {
'current_content_length': self._current_content_length,
'is_last': self._is_last,
'server': self._request_builder.GetServer(),
'upload_url': self._upload_url,
'version': self._request_builder.GetVersion()
}
try:
yaml.dump(d... | 152,673 |
Uploads operations to the given uploadUrl in incremental steps.
Note: Each list of operations is expected to contain operations of the
same type, similar to how one would normally send operations in an
AdWords API Service request.
Args:
operations: one or more lists of operations as would be sen... | def UploadOperations(self, operations, is_last=False):
if self._is_last:
raise googleads.errors.AdWordsBatchJobServiceInvalidOperationError(
'Can\'t add new operations to a completed incremental upload.')
# Build the request
req = self._request_builder.BuildUploadRequest(
self._... | 152,674 |
Extract fields used in the summary logs.
Args:
request: a urllib2.Request instance configured to make the request.
[optional]
error: a urllib2.HttpError instance used to retrieve error details.
Returns:
A dict containing the fields to be output in the summary logs. | def _ExtractRequestSummaryFields(self, request, error=None):
headers = request.headers
summary_fields = {
'server': request.get_full_url(),
'contentRange': headers['Content-range'],
'contentLength': headers['Content-length']
}
if error:
summary_fields['isError'] = Tru... | 152,675 |
Creates a WHERE builder using a provided field.
Args:
field: the field to be added as an argument in the WHERE clause.
Returns:
The created WHERE builder. | def Where(self, field):
where_builder = _WhereBuilder(self, field)
self.where_builders.append(where_builder)
return where_builder | 152,677 |
Creates the WHERE builder with specified query builder and field.
This class should be instantiated through _QueryBuilder.Where. Don't call
this constructor directly.
Args:
query_builder: The query builder that this WHERE builder links to.
field: The field to be used in the WHERE condition.
... | def __init__(self, query_builder, field):
self._field = field
self._query_builder = query_builder
self._awql = None | 152,678 |
Sets the type of the WHERE clause as "equal to".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def EqualTo(self, value):
self._awql = self._CreateSingleValueCondition(value, '=')
return self._query_builder | 152,679 |
Sets the type of the WHERE clause as "not equal to".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def NotEqualTo(self, value):
self._awql = self._CreateSingleValueCondition(value, '!=')
return self._query_builder | 152,680 |
Sets the type of the WHERE clause as "greater than".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def GreaterThan(self, value):
self._awql = self._CreateSingleValueCondition(value, '>')
return self._query_builder | 152,681 |
Sets the type of the WHERE clause as "greater than or equal to".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def GreaterThanOrEqualTo(self, value):
self._awql = self._CreateSingleValueCondition(value, '>=')
return self._query_builder | 152,682 |
Sets the type of the WHERE clause as "less than".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def LessThan(self, value):
self._awql = self._CreateSingleValueCondition(value, '<')
return self._query_builder | 152,683 |
Sets the type of the WHERE clause as "less than or equal to.
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def LessThanOrEqualTo(self, value):
self._awql = self._CreateSingleValueCondition(value, '<=')
return self._query_builder | 152,684 |
Sets the type of the WHERE clause as "starts with".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def StartsWith(self, value):
self._awql = self._CreateSingleValueCondition(value, 'STARTS_WITH')
return self._query_builder | 152,685 |
Sets the type of the WHERE clause as "starts with ignore case".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def StartsWithIgnoreCase(self, value):
self._awql = self._CreateSingleValueCondition(value,
'STARTS_WITH_IGNORE_CASE')
return self._query_builder | 152,686 |
Sets the type of the WHERE clause as "contains".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def Contains(self, value):
self._awql = self._CreateSingleValueCondition(value, 'CONTAINS')
return self._query_builder | 152,687 |
Sets the type of the WHERE clause as "contains ignore case".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def ContainsIgnoreCase(self, value):
self._awql = self._CreateSingleValueCondition(value, 'CONTAINS_IGNORE_CASE')
return self._query_builder | 152,688 |
Sets the type of the WHERE clause as "does not contain".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def DoesNotContain(self, value):
self._awql = self._CreateSingleValueCondition(value, 'DOES_NOT_CONTAIN')
return self._query_builder | 152,689 |
Sets the type of the WHERE clause as "doesn not contain ignore case".
Args:
value: The value to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def DoesNotContainIgnoreCase(self, value):
self._awql = self._CreateSingleValueCondition(
value, 'DOES_NOT_CONTAIN_IGNORE_CASE')
return self._query_builder | 152,690 |
Sets the type of the WHERE clause as "in".
Args:
*values: The values to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def In(self, *values):
self._awql = self._CreateMultipleValuesCondition(values, 'IN')
return self._query_builder | 152,691 |
Sets the type of the WHERE clause as "in".
Args:
*values: The values to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def NotIn(self, *values):
self._awql = self._CreateMultipleValuesCondition(values, 'NOT_IN')
return self._query_builder | 152,692 |
Sets the type of the WHERE clause as "contains any".
Args:
*values: The values to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def ContainsAny(self, *values):
self._awql = self._CreateMultipleValuesCondition(values, 'CONTAINS_ANY')
return self._query_builder | 152,693 |
Sets the type of the WHERE clause as "contains none".
Args:
*values: The values to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def ContainsNone(self, *values):
self._awql = self._CreateMultipleValuesCondition(values, 'CONTAINS_NONE')
return self._query_builder | 152,694 |
Sets the type of the WHERE clause as "contains all".
Args:
*values: The values to be used in the WHERE condition.
Returns:
The query builder that this WHERE builder links to. | def ContainsAll(self, *values):
self._awql = self._CreateMultipleValuesCondition(values, 'CONTAINS_ALL')
return self._query_builder | 152,695 |
A page generator for this service query and the provided service.
This generates a page as a result from using the provided service's query()
method until there are no more results to fetch.
Args:
service: The service object for making a query using this service query.
Yields:
A resulting... | def Pager(self, service):
has_page = True
while has_page:
page = service.query(self)
yield page
has_page = self.HasNext(page)
if has_page:
self.NextPage() | 152,701 |
Update the credentials associated with application user.
Args:
client_id: str Client Id retrieved from the developer's console.
client_secret: str Client Secret retrieved from the developer's console.
refresh_token: str Refresh token generated with the above client id/secret.
adwords_manager_cid: str... | def UpdateUserCredentials(client_id, client_secret, refresh_token,
adwords_manager_cid, developer_token):
app_user = AppUser.query(AppUser.user == users.get_current_user()).fetch()[0]
app_user.client_id = client_id
app_user.client_secret = client_secret
app_user.refresh_token = ref... | 152,705 |
Creates a default partition.
Args:
client: an AdWordsClient instance.
ad_group_id: an integer ID for an ad group. | def CreateDefaultPartition(client, ad_group_id):
ad_group_criterion_service = client.GetService('AdGroupCriterionService',
version='v201809')
operations = [{
'operator': 'ADD',
'operand': {
'xsi_type': 'BiddableAdGroupCriterion',
'... | 152,710 |
Sanitizes a field value from a Value object to a CSV suitable format.
Args:
pql_value: dict a dictionary containing the data for a single field of an
entity.
Returns:
str a CSV writer friendly value formatted by Value.Type. | def ConvertValueForCsv(pql_value):
if 'value' in pql_value:
field = pql_value['value']
elif 'values' in pql_value:
field = pql_value['values']
else:
field = None
if field:
if isinstance(field, list):
return ','.join(['"%s"' % str(ConvertValueForCsv(single_field))
... | 152,713 |
Converts the PQL formatted response for a dateTime object.
Output conforms to ISO 8061 format, e.g. 'YYYY-MM-DDTHH:MM:SSz.'
Args:
date_time_value: dict The date time value from the PQL response.
Returns:
str: A string representation of the date time value uniform to
ReportService. | def ConvertDateTimeToOffset(date_time_value):
date_time_obj = datetime(int(date_time_value['date']['year']),
int(date_time_value['date']['month']),
int(date_time_value['date']['day']),
int(date_time_value['hour']),
... | 152,714 |
Creates a user identifier from the specified type and value.
Args:
identifier_type: a str specifying the type of user identifier.
value: a str value of the identifier; to be hashed using SHA-256 if needed.
Returns:
A dict specifying a user identifier, with a value hashed using SHA-256 if
needed. | def _CreateUserIdentifier(identifier_type=None, value=None):
if identifier_type in _HASHED_IDENTIFIER_TYPES:
# If the user identifier type is a hashed type, normalize and hash the
# value.
value = hashlib.sha256(value.strip().lower()).hexdigest()
user_identifier = {
'userIdentifierType': ident... | 152,720 |
Retrieve the index of a given field in the api_error's fieldPathElements.
Args:
api_error: a dict containing a partialFailureError returned from the AdWords
API.
field: a str field for which this determines the index in the api_error's
fieldPathElements.
Returns:
An int index of the field ... | def _GetFieldPathElementIndex(api_error, field):
field_path_elements = api_error['fieldPathElements']
if field_path_elements:
found_index = [field_path_element['index']
for field_path_element in field_path_elements
if field_path_element['field'] == field]
if found_i... | 152,721 |
Overrides the ingress function for response logging.
Args:
envelope: An Element with the SOAP request data.
http_headers: A dict of the current http headers.
operation: The SoapOperation instance.
Returns:
A tuple of the envelope and headers. | def ingress(self, envelope, http_headers, operation):
if self._logger.isEnabledFor(logging.DEBUG):
self._logger.debug(_RESPONSE_XML_LOG_LINE,
etree.tostring(envelope, pretty_print=True))
if self._logger.isEnabledFor(logging.WARN):
warn_data = {}
header = envelope... | 152,756 |
Overrides the egress function ror request logging.
Args:
envelope: An Element with the SOAP request data.
http_headers: A dict of the current http headers.
operation: The SoapOperation instance.
binding_options: An options dict for the SOAP binding.
Returns:
A tuple of the envelo... | def egress(self, envelope, http_headers, operation, binding_options):
if self._logger.isEnabledFor(logging.INFO):
service_name = operation.binding.wsdl.services.keys()[0]
self._logger.info(_REQUEST_LOG_LINE, service_name, operation.name,
binding_options['address'])
if s... | 152,757 |
Restrict a feed item to a geo target location.
Args:
client: An AdWordsClient instance.
feed_item: A FeedItem.
location_id: The Id of the location to restrict to. | def RestrictFeedItemToGeoTarget(client, feed_item, location_id):
# Retrieve the FeedItemTargetService
feed_item_target_service = client.GetService(
'FeedItemTargetService', version='v201809')
# Optional: Restrict the first feed item to only serve with ads for the
# specified geo target.
criterion_ta... | 152,764 |
Adds a new Smart Shopping campaign.
Args:
client: an AdWordsClient instance.
budget_id: the str ID of the budget to be associated with the Shopping
campaign.
merchant_id: the str ID of the merchant account to be associated with the
Shopping campaign.
Returns:
A campaign ID. | def CreateSmartCampaign(client, budget_id, merchant_id):
campaign_service = client.GetService('CampaignService', version='v201809')
# Create campaign with required and optional settings.
campaign = {
'name': 'Shopping campaign #%s' % uuid.uuid4(),
# The advertisingChannelType is what makes this a S... | 152,774 |
Adds a new Smart Shopping ad group.
Args:
client: an AdWordsClient instance.
campaign_id: the str ID of a Smart Shopping campaign.
Returns:
An ad group ID. | def CreateSmartShoppingAdGroup(client, campaign_id):
ad_group_service = client.GetService('AdGroupService', version='v201809')
# Create the ad group.
ad_group = {
'campaignId': campaign_id,
'name': 'Smart Shopping ad group #%s' % uuid.uuid4(),
# Set the ad group type to SHOPPING_GOAL_OPTIMIZE... | 152,775 |
Adds a new Smart Shopping ad.
Args:
client: an AdWordsClient instance.
ad_group_id: an integer ID for an ad group. | def CreateSmartShoppingAd(client, ad_group_id):
ad_group_ad_service = client.GetService('AdGroupAdService', version='v201809')
# Create an AdGroup Ad.
adgroup_ad = {
'adGroupId': ad_group_id,
# Create a Smart Shopping ad (Goal-optimized Shopping ad).
'ad': {
'xsi_type': 'GoalOptimiz... | 152,776 |
A simple convenience utility for adding months to a given start date.
This increments the months by adding the number of days in the current month
to the current month, for each month.
Args:
start_date: date The date months are being added to.
months: int The number of months to add.
Returns:
A d... | def AddMonths(start_date, months):
current_date = start_date
i = 0
while i < months:
month_days = calendar.monthrange(current_date.year, current_date.month)[1]
current_date += timedelta(days=month_days)
i += 1
return current_date | 152,783 |
Displays mean average cpc, position, clicks, and total cost for estimate.
Args:
message: str message to display for the given estimate.
min_estimate: sudsobject containing a minimum estimate from the
TrafficEstimatorService response.
max_estimate: sudsobject containing a maximum estimate from the
... | def DisplayEstimate(message, min_estimate, max_estimate):
# Find the mean of the min and max values.
mean_avg_cpc = (_CalculateMean(min_estimate['averageCpc']['microAmount'],
max_estimate['averageCpc']['microAmount'])
if 'averageCpc' in min_estimate
... | 152,788 |
Format a SOAP DateTime object for printing.
Args:
value: The DateTime object to format.
Returns:
A string representing the value. | def FormatSOAPDateTime(value):
value_date = value['date']
return '%s-%s-%s %s:%s:%s (%s)' % (
value_date['year'], value_date['month'], value_date['day'],
value['hour'], value['minute'], value['second'], value['timeZoneId']) | 152,796 |
Calculate forecast percentage stats.
Args:
matched: The number of matched impressions.
available: The number of available impressions.
possible: The optional number of possible impressions.
Returns:
The percentage of impressions that are available and possible. | def CalculateForecastStats(matched, available, possible=None):
if matched > 0:
available_percent = (float(available) / matched) * 100.
else:
available_percent = 0
if possible is not None:
if matched > 0:
possible_percent = (possible/float(matched)) * 100.
else:
possible_percent = 0... | 152,797 |
Creates a shopping campaign with the given budget and merchant IDs.
Args:
client: an AdWordsClient instance.
budget_id: the str ID of the budget to be associated with the shopping
campaign.
merchant_id: the str ID of the merchant account to be associated with the
shopping campaign.
Returns... | def CreateShoppingCampaign(client, budget_id, merchant_id):
campaign_service = client.GetService('CampaignService', 'v201809')
campaign = {
'name': 'Shopping campaign #%s' % uuid.uuid4(),
# The advertisingChannelType is what makes this a shopping campaign
'advertisingChannelType': 'SHOPPING',
... | 152,803 |
Creates an AdGroup for the given shopping campaign ID.
Args:
client: an AdWordsClient instance.
campaign_id: the str ID of a shopping campaign.
Returns:
The created AdGroup as a sudsobject. | def CreateAdGroup(client, campaign_id):
ad_group_service = client.GetService('AdGroupService', 'v201809')
adgroup = {
# Required: Set the ad group type to SHOPPING_SHOWCASE_ADS
'adGroupType': 'SHOPPING_SHOWCASE_ADS',
'campaignId': campaign_id,
'name': 'AdGroup #%s' % uuid.uuid4(),
... | 152,804 |
Creates a showcase add for the given AdGroup with the given images.
Args:
client: an AdWordsClient instance.
adgroup: a dict or suds object defining an AdGroup for a Shopping Campaign.
expanded_image_filepath: a str filepath to a .jpg file that will be used as
the Showcase Ad's expandedImage.
c... | def CreateShowcaseAd(client, adgroup, expanded_image_filepath,
collapsed_image_filepath):
ad_group_ad_service = client.GetService('AdGroupAdService', 'v201809')
showcase_ad = {
'adGroupId': adgroup['id'],
'ad': {
'xsi_type': 'ShowcaseAd',
'Ad.Type': 'Showcase... | 152,805 |
Uploads a .jpg image with the given filepath via the AdWords MediaService.
Args:
client: an AdWordsClient instance.
filepath: a str filepath to the .jpg file to be uploaded.
Returns:
The created Image as a sudsobject. | def UploadImage(client, filepath):
media_service = client.GetService('MediaService', 'v201809')
with open(filepath, 'rb') as image_handle:
image_data = image_handle.read().decode('utf-8')
image = [{
'xsi_type': 'Image',
'data': image_data,
'type': 'IMAGE'
}]
image = media_service.u... | 152,806 |
Creates a ProductPartition tree for the given AdGroup ID.
Args:
client: an AdWordsClient instance.
adgroup_id: a str AdGroup ID.
Returns:
The ProductPartition tree as a sudsobject. | def CreateProductPartition(client, adgroup_id):
ad_group_criterion_service = client.GetService('AdGroupCriterionService',
'v201809')
helper = ProductPartitionHelper(adgroup_id)
root = helper.CreateSubdivision()
new_product_canonical_condition = {
'xsi_t... | 152,807 |
Initializer.
Args:
adgroup_id: The ID of the AdGroup that we wish to attach the partition
tree to. | def __init__(self, adgroup_id):
# The next temporary criterion ID to be used.
# When creating our tree we need to specify the parent-child relationships
# between nodes. However, until a criterion has been created on the server
# we do not have a criterion ID with which to refer to it.
# Instea... | 152,808 |
Creates a subdivision node.
Args:
parent: The node that should be this node's parent.
value: The value being partitioned on.
Returns:
A new subdivision node. | def CreateSubdivision(self, parent=None, value=None):
division = {
'xsi_type': 'ProductPartition',
'partitionType': 'SUBDIVISION',
'id': str(self.next_id)
}
# The root has neither a parent nor a value.
if parent is not None:
division['parentCriterionId'] = parent['id'... | 152,809 |
Creates a unit node.
Args:
parent: The node that should be this node's parent.
value: The value being partitioned on.
bid_amount: The amount to bid for matching products, in micros.
Returns:
A new unit node. | def CreateUnit(self, parent=None, value=None, bid_amount=None):
unit = {
'xsi_type': 'ProductPartition',
'partitionType': 'UNIT'
}
# The root node has neither a parent nor a value.
if parent is not None:
unit['parentCriterionId'] = parent['id']
unit['caseValue'] = value... | 152,810 |
Creates the budget.
Args:
client: an AdWordsClient instance.
Returns:
a suds.sudsobject.Object representation of the created budget. | def _CreateBudget(client):
budget_service = client.GetService('BudgetService', version='v201809')
# Create the campaign budget
operation = {
'operand': {
'name': 'Interplanetary Cruise Budget #%d' % uuid.uuid4(),
'deliveryMethod': 'STANDARD',
'amount': {
'micr... | 152,845 |
Creates the campaign.
Args:
client: an AdWordsClient instance.
budget: a suds.sudsobject.Object representation of a created budget.
Returns:
An integer campaign ID. | def _CreateCampaign(client, budget):
campaign_service = client.GetService('CampaignService')
operations = [{
'operator': 'ADD',
'operand': {
'name': 'Interplanetary Cruise #%d' % uuid.uuid4(),
# Recommendation: Set the campaign to PAUSED when creating it to
# prevent th... | 152,846 |
Creates an ad group.
Args:
client: an AdWordsClient instance.
campaign_id: an integer campaign ID.
Returns:
An integer ad group ID. | def _CreateAdGroup(client, campaign_id):
ad_group_service = client.GetService('AdGroupService')
operations = [{
'operator': 'ADD',
'operand': {
'campaignId': campaign_id,
'adGroupType': 'SEARCH_DYNAMIC_ADS',
'name': 'Earth to Mars Cruises #%d' % uuid.uuid4(),
... | 152,847 |
Creates the expanded Dynamic Search Ad.
Args:
client: an AdwordsClient instance.
ad_group_id: an integer ID of the ad group in which the DSA is added. | def _CreateExpandedDSA(client, ad_group_id):
# Get the AdGroupAdService.
ad_group_ad_service = client.GetService('AdGroupAdService')
# Create the operation
operations = [{
'operator': 'ADD',
'operand': {
'xsi_type': 'AdGroupAd',
'adGroupId': ad_group_id,
# Create th... | 152,848 |
Adds a web page criterion to target Dynamic Search Ads.
Args:
client: an AdWordsClient instance.
ad_group_id: an integer ID of the ad group the criteria is being added to. | def _AddWebPageCriteria(client, ad_group_id):
ad_group_criterion_service = client.GetService('AdGroupCriterionService',
version='v201809')
operations = [{
'operator': 'ADD',
# Create biddable ad group criterion.
'operand': {
'xsi_type'... | 152,849 |
Uploads the image from the specified url.
Args:
client: An AdWordsClient instance.
url: The image URL.
Returns:
The ID of the uploaded image. | def UploadImageAsset(client, url):
# Initialize appropriate service.
asset_service = client.GetService('AssetService', version='v201809')
# Download the image.
image_request = requests.get(url)
# Create the image asset.
image_asset = {
'xsi_type': 'ImageAsset',
'imageData': image_request.co... | 152,854 |
Generates a library signature suitable for a user agent field.
Args:
short_name: The short, product-specific string name for the library.
Returns:
A library signature string to append to user-supplied user-agent value. | def GenerateLibSig(short_name):
with _UTILITY_LOCK:
utilities_used = ', '.join([utility for utility
in sorted(_utility_registry)])
_utility_registry.Clear()
if utilities_used:
return ' (%s, %s, %s, %s)' % (short_name, _COMMON_LIB_SIG, _PYTHON_VERSION,
... | 152,859 |
Generates an GoogleOAuth2Client subclass using the given product_data.
Args:
product_yaml_key: a string key identifying the product being configured.
product_data: a dict containing the configurations for a given product.
proxy_config: a ProxyConfig instance.
Returns:
An instantiated GoogleOAuth2C... | def _ExtractOAuth2Client(product_yaml_key, product_data, proxy_config):
oauth2_kwargs = {
'proxy_config': proxy_config
}
if all(config in product_data for config in _OAUTH2_INSTALLED_APP_KEYS):
oauth2_args = [
product_data['client_id'], product_data['client_secret'],
product_data['re... | 152,862 |
Recurses over a nested structure to look for changes in Suds objects.
Args:
obj: A parameter for a SOAP request field which is to be inspected and
will be packed for Suds if an xsi_type is specified, otherwise will be
left unaltered.
factory: The suds.client.Factory object which can create in... | def _RecurseOverObject(obj, factory, parent=None):
if _IsSudsIterable(obj):
# Since in-place modification of the Suds object is taking place, the
# iterator should be done over a frozen copy of the unpacked fields.
copy_of_obj = tuple(obj)
for item in copy_of_obj:
if _IsSudsIterable(item):
... | 152,865 |
Extract logging fields from the request's suds.sax.element.Element.
Args:
document: A suds.sax.element.Element instance containing the API request.
Returns:
A dict mapping logging field names to their corresponding value. | def _ExtractRequestSummaryFields(document):
headers = document.childAtPath('Header/RequestHeader')
body = document.childAtPath('Body')
summary_fields = {
'methodName': body.getChildren()[0].name
}
# Extract AdWords-specific fields if they exist.
# Note: We need to check if None because this will ... | 152,867 |
Extract logging fields from the response's suds.sax.document.Document.
Args:
document: A suds.sax.document.Document instance containing the parsed
API response for a given API request.
Returns:
A dict mapping logging field names to their corresponding value. | def _ExtractResponseSummaryFields(document):
headers = document.childAtPath('Envelope/Header/ResponseHeader')
body = document.childAtPath('Envelope/Body')
summary_fields = {}
if headers is not None:
summary_fields['requestId'] = headers.getChild('requestId').text
summary_fields['responseTime'] = hea... | 152,868 |
Initializes _ZeepProxyTransport.
Args:
timeout: An integer timeout in MS for connections.
proxy_config: A ProxyConfig instance representing proxy settings.
cache: A zeep.cache.Base instance representing a cache strategy to employ. | def __init__(self, timeout, proxy_config, cache):
if not cache:
cache = zeep.cache.SqliteCache()
elif cache == ZeepServiceProxy.NO_CACHE:
cache = None
super(_ZeepProxyTransport, self).__init__(
timeout=timeout, operation_timeout=timeout, cache=cache)
self.session.proxies = pro... | 152,873 |
Initializes SudsHTTPSTransport.
Args:
timeout: An integer for the connection timeout time.
proxy_config: A ProxyConfig instance representing proxy settings. | def __init__(self, timeout, proxy_config):
suds.transport.http.HttpTransport.__init__(self, timeout=timeout)
self.handlers = proxy_config.GetHandlers() | 152,874 |
Return an XML string representing a SOAP complex type.
Args:
type_name: The name of the type with namespace prefix if necessary.
value: A python dictionary to hydrate the type instance with.
Returns:
A string containing the SOAP XML for the type. | def GetSoapXMLForComplexType(self, type_name, value):
schema = self.suds_client.wsdl.schema
definition_type = schema.elements[(type_name, self._namespace_override)]
marshaller = suds.mx.literal.Literal(schema)
content = suds.mx.Content(
tag=type_name, value=value,
name=type_name, ty... | 152,877 |
Return an XML string representing a SOAP complex type.
Args:
type_name: The name of the type with namespace prefix if necessary.
value: A python dictionary to hydrate the type instance with.
Returns:
A string containing the SOAP XML for the type. | def GetSoapXMLForComplexType(self, type_name, value):
element = self.schema.get_element(
'{%s}%s' % (self._namespace_override, type_name))
result_element = self._element_maker(element.qname.localname)
element_value = element(**value)
element.type.render(result_element, element_value)
da... | 152,879 |
Initializes a SOAP service.
Args:
header_handler: A googleads.common.HeaderHandler instance used to set
SOAP and HTTP headers.
packer: A googleads.common.SoapPacker instance used to transform
entities.
version: the version of the current API, e.g. 'v201811' | def __init__(self, header_handler, packer, version):
self._header_handler = header_handler
self._packer = packer
self._version = version
self._method_proxies = {} | 152,880 |
Get the raw SOAP XML for a request.
Args:
method: The method name.
*args: A list of arguments to be passed to the method.
Returns:
An element containing the raw XML that would be sent as the request. | def GetRequestXML(self, method, *args):
self.suds_client.set_options(nosend=True)
service_request = (getattr(self, method))(*args).envelope
self.suds_client.set_options(nosend=False)
return lxml.etree.fromstring(service_request) | 152,883 |
Set the headers for the underlying client.
Args:
soap_headers: A SOAP element for the SOAP headers.
http_headers: A dictionary for the http headers. | def SetHeaders(self, soap_headers, http_headers):
self.suds_client.set_options(soapheaders=soap_headers, headers=http_headers) | 152,884 |
Determine if the wsdl contains a method.
Args:
method_name: The name of the method to search.
Returns:
True if the method is in the WSDL, otherwise False. | def _WsdlHasMethod(self, method_name):
return method_name in self.suds_client.wsdl.services[0].ports[0].methods | 152,885 |
Create a method wrapping an invocation to the SOAP service.
Args:
method_name: A string identifying the name of the SOAP method to call.
Returns:
A callable that can be used to make the desired SOAP request. | def _CreateMethod(self, method_name):
soap_service_method = getattr(self.suds_client.service, method_name)
def MakeSoapRequest(*args):
AddToUtilityRegistry('suds')
self.SetHeaders(
self._header_handler.GetSOAPHeaders(self.CreateSoapElementForType),
self._header_handl... | 152,886 |
Overriding the egress function to set our headers.
Args:
envelope: An Element with the SOAP request data.
http_headers: A dict of the current http headers.
operation: The SoapOperation instance.
binding_options: An options dict for the SOAP binding.
Returns:
A tuple of the envelo... | def egress(self, envelope, http_headers, operation, binding_options):
custom_headers = self._header_handler.GetHTTPHeaders()
http_headers.update(custom_headers)
return envelope, http_headers | 152,887 |
Get the raw SOAP XML for a request.
Args:
method: The method name.
*args: A list of arguments to be passed to the method.
Returns:
An element containing the raw XML that would be sent as the request. | def GetRequestXML(self, method, *args):
packed_args = self._PackArguments(method, args, set_type_attrs=True)
headers = self._GetZeepFormattedSOAPHeaders()
return self.zeep_client.create_message(
self.zeep_client.service, method, *packed_args, _soapheaders=headers) | 152,889 |
Determine if a method is in the wsdl.
Args:
method_name: The name of the method.
Returns:
True if the method is in the wsdl, otherwise False. | def _WsdlHasMethod(self, method_name):
try:
self._method_bindings.get(method_name)
return True
except ValueError:
return False | 152,890 |
An imperfect but decent method for determining if a string is base64.
Args:
s: A string with the data to test.
Returns:
True if s is base64, else False. | def _IsBase64(cls, s):
try:
if base64.b64encode(base64.b64decode(s)).decode('utf-8') == s:
return True
except (TypeError, binascii.Error):
pass
return False | 152,893 |
Recursive helper for PackArguments.
Args:
elem: The element type we are creating.
data: The data to instantiate it with.
set_type_attrs: A boolean indicating whether or not attributes that end
in .Type should be set. This is only necessary for batch job service.
Returns:
An ins... | def _PackArgumentsHelper(self, elem, data, set_type_attrs):
if self._packer:
data = self._packer.Pack(data, self._version)
if isinstance(data, dict): # Instantiate from simple Python dict
# See if there is a manually specified derived type.
type_override = data.get('xsi_type')
if ... | 152,894 |
Searches all namespaces for a type by name.
Args:
type_localname: The name of the type.
Returns:
A fully qualified SOAP type with the specified name.
Raises:
A zeep.exceptions.LookupError if the type cannot be found in any
namespace. | def _DiscoverElementTypeFromLocalname(self, type_localname):
elem_type = None
last_exception = None
for ns_prefix in self.zeep_client.wsdl.types.prefix_map.values():
try:
elem_type = self.zeep_client.get_type(
'{%s}%s' % (ns_prefix, type_localname))
except zeep.exception... | 152,895 |
Initialize a SOAP element with specific data.
Args:
elem_type: The type of the element to create.
type_is_override: A boolean specifying if the type is being overridden.
data: The data to hydrate the type with.
set_type_attrs: A boolean indicating whether or not attributes that end
... | def _CreateComplexTypeFromData(
self, elem_type, type_is_override, data, set_type_attrs):
elem_arguments = dict(elem_type.elements)
# A post order traversal of the original data, need to instantiate from
# the bottom up.
instantiated_arguments = {
k: self._PackArgumentsHelper(elem_ar... | 152,896 |
Create a method wrapping an invocation to the SOAP service.
Args:
method_name: A string identifying the name of the SOAP method to call.
Returns:
A callable that can be used to make the desired SOAP request. | def _CreateMethod(self, method_name):
soap_service_method = self.zeep_client.service[method_name]
def MakeSoapRequest(*args):
AddToUtilityRegistry('zeep')
soap_headers = self._GetZeepFormattedSOAPHeaders()
packed_args = self._PackArguments(method_name, args)
try:
return soa... | 152,898 |
Recursively display a node and each of its children.
Args:
node: The node we're displaying the children of.
children: Children of the parent node.
level: How deep in the tree we are. | def DisplayTree(node, children, level=0):
value = ''
node_type = ''
if 'caseValue' in node:
case_value = node['caseValue']
node_type = case_value['ProductDimension.Type']
if node_type == 'ProductCanonicalCondition':
value = (case_value['condition'] if 'condition' in case_value
... | 152,902 |
Download all ad units.
Args:
inventory_service: An instance of the InventoryService.
Returns:
A list containing all ad units. | def get_all_ad_units(inventory_service):
# Create a statement to get all ad units.
statement = (ad_manager.StatementBuilder(version='v201811')
.OrderBy('id', ascending=True))
# Pull down all ad units into a list
keep_iterating = True
total_results = 0
found_ad_units = []
while keep_iter... | 152,911 |
Display the ad units as a tree.
Args:
root_ad_unit: The root ad unit to begin from.
all_ad_units: A list containing all ad units. | def display_hierarchy(root_ad_unit, all_ad_units):
# Create a dict mapping the ids of parents to lists of their children.
parent_id_to_children = collections.defaultdict(list)
for ad_unit in all_ad_units:
if 'parentId' in ad_unit:
parent_id_to_children[ad_unit['parentId']].append(ad_unit)
parent_id... | 152,912 |
Recursive helper for displaying the hierarchy.
Args:
root: The current root ad unit.
parent_id_to_children: The overall map of parent ids to children.
depth: The current depth. | def display_hierarchy_helper(root, parent_id_to_children, depth):
print '%s%s (%s)' % ('%s+--' % ('|'.join([' '] * depth)),
root['name'], root['id'])
# Recurse for each child of this root that has children.
for child in parent_id_to_children.get(root['id'], []):
display_hierarchy_h... | 152,913 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.