Google Postmaster Domains Datas
- class googlepostmasterapi.gpt.GPostmaster(token, pool_size=2, verbose=False)
Download datas from Google postmaster tools
- _uri_tpl
Template to create an uri to get domain infos
- Type:
string
- _domains
All domains download from server
- Type:
string[]
- _service
Connector to GPT
- Type:
googleapiclient.discovery.build
- _pool_size
Pool size to calls
- Type:
int
- __init__(token, pool_size=2, verbose=False)
Default constructor
- Parameters:
token (string) – Absolute file path to GPT token
verbose (bool) – Verbose mode. Default to False
- _clean_domain_infos(key, datas)
Clean domain infos
- Parameters:
key (string) – Key to identify datas on cleaner
datas (dict) – Domain infos to clean
- Returns:
Cleaned datas
- Return type:
dict
- _clean_pool_returns(datas)
Clean result from pool map returns : remove all state==false
- Parameters:
datas (dict[]) – List of dict from pool map
- Returns:
List of dict from pool map with only state==true
- Return type:
dict[]
- _create_domain_uri(domain, input_date)
Create URI to a domain to query
- Parameters:
domain (string) – Domain to query
input_date (string) – Date to query, format : YYYYMMDD
- _create_pool_datas(input_date)
Create datas to map call on pool with all domains
- Parameters:
input_date (string) – Date to query
- Returns:
List of dict with domain&input_date
- Return type:
dict[]
- _get_domain_infos_pool(datas)
Abstract call to get_domain_infos from pool with datas as dict
- Parameters:
datas (dict) – Values domain/input_date to send to get_domain_infos
- Returns:
Result from get_domain_infos calls
- Return type:
dict
- _gpt_get_domain_info(domain, input_date)
Call GPT to get all infos to a domain
- Parameters:
domain (string) – Domain to query
input_date (string) – Date to query, format : YYYYMMDD
- Returns:
Process state & result
- Return type:
dict
- _gpt_get_domains()
Call GPT to get all domains
- Returns:
List of dict with all domains, format : [ { ‘name’: …, ‘createTime’: …, ‘permission’: … } ]
- Return type:
list
- _init_parser_con()
Init datas parser/cleaner con
- _init_resources(token)
Init resources used by system : init service / parser / stats
- Parameters:
token (string) – Absolute file path to GPT token
- _init_service(token)
Init service connector
- Parameters:
token (string) – Absolute file path to GPT token
- _init_stats_con()
Init stats con. Should be manager by multiprocessing to work with pool
- _load_token(token)
Load GPT token
- Parameters:
token (string) – Absolute file path to GPT token
- _print_stats()
Display calls statistics
- get_all_domains_infos(input_date)
Call GPT on all available domains
- Parameters:
input_date (string) – Date to query, format : YYYYMMDD
- Returns:
All domain infos
- Return type:
list
- get_domain_infos(domain, input_date, print_stats=True)
Get infos to a domain
- Parameters:
domain (string) – Domain to query
input_date (string) – Date to query, format : YYYYMMDD
print_stats (bool) – True to display stats of the call. Defaut : True
- Returns:
Process state & domain infos
- Return type:
dict
- get_domains()
Get all domains with permissions : owner/reader
- verbose
Template to create an uri to get domain infos
- class googlepostmasterapi.datas.FlatDatas
Clean datas traffic stats from Google Postmaster Tools
- datas
Datas cleaned
- Type:
dict
- _datas_tpl
Template to clean datas
- Type:
dict
- dict_reputation
Assoc to translate EN reputation to int
- Type:
dict
- __init__()
Default constructor
- _parse_crypted_inbound(key, value)
Clean part of key : inboundEncryptionRatio
- Parameters:
key (string) – Key to identify datas
value (float) – Inbound encrypted ratio to convert to percent
- Returns:
False if no value to convert. True otherwise
- Return type:
bool
- _parse_delivery_err(key, value)
Clean part of key : deliveryErrors
- Parameters:
key (string) – Key to identify datas
value (dict[]) – Array with all delivery error ratio to convert to percent
- Returns:
False if no value to convert. True otherwise
- Return type:
bool
- _parse_domain_reputations(key, value)
Clean part of key : domainReputation
- Parameters:
key (string) – Key to identify datas
value (string) – Domain reputation
- Returns:
False if no value to convert. True otherwise
- Return type:
bool
- _parse_feed_back_loop(key, value)
Clean part of key : spammyFeedbackLoops
- Parameters:
key (string) – Key to identify datas
value (dict[]) – Array with all feedback loop splitted by uid
- Returns:
False if no value to convert. True otherwise
- Return type:
bool
- _parse_ips_reputations(key, value)
Clean part of key : ipReputations
- Parameters:
key (string) – Key to identify datas
value (dict[]) – Array with all four reputations : bad/low/medium/high
- Returns:
False if no value to convert. True otherwise
- Return type:
bool
- _parse_use_auth(key, **kargs)
Clean part of keys : dkimSuccessRatio / spfSuccessRatio / dmarcSuccessRatio
- Parameters:
key (string) – Key to identify datas
dkim (float) – DKIM ratio to convert to percent. Optional
spf (float) – SPF ratio to convert to percent. Optional
dmarc (float) – DMARC ratio to convert to percent. Optional
- Returns:
True if at leat one the three key exists. False otherwise
- Return type:
bool
- _parse_user_report_spam(key, value)
Clean part of key : userReportedSpamRatio
- Parameters:
key (string) – Key to identify datas
value (float) – Report ratio to convrt to percent
- Returns:
False if no value to convert. True otherwise
- Return type:
bool
- parse(key, datas)
Parse datas from GPT to a flatern version with all values
- Parameters:
key (string) – Key to identify datas
datas (dict) – Datas from GPT to clean
- Returns:
Cleaned datas from GPT
- Return type:
dict
- class googlepostmasterapi.stats.Stats
Process stats of GPostmaster
- datas
Statistics from domains infos download
- Type:
dict
- __init__()
Default constructor
- add_err()
Increment counters : total + err
- add_err_http(code, err, domain)
Increment counters : total + err & add domain to http error datas
- Parameters:
code (int) – Http code
err (string) – Http error message
domain (string) – Domain to add to http error
- add_ok()
Increment counters : total + ok
- add_total()
Increment counter : total
- print_stats()
Display calls statistics
- Returns:
False if nothing to display. True otherwise
- Return type:
bool
- googlepostmasterapi.utils.write_std(logs)
Quick write on stdout
- Parameters:
logs (string[]) – List of log to print on stdout