协助连接指挥探照灯API的客户

searchlight-api的Python项目详细描述


searchlight api客户端python

Latest Version

searchlight api客户机是一个python包,它使得通过conductor searchlightapi进行身份验证和从中检索数据变得非常容易。

开始

安装

最新发布的版本可以通过python包索引安装。

pip install searchlight-api

依赖性

认证

Searchlight API客户端需要知道API密钥和API密钥才能使用Searchlight进行身份验证它可以通过以下两种方式之一找到它们:

  • 将凭据添加到环境变量(首选)
  • 在实例化API客户端时传递凭据 从searchlight_api.client导入AccountService 帐户服务=帐户服务(api_key=xxxxx,secret=xxxxx)

如果没有API密钥和机密,请从http://developers.conductor.com/请求一个你应该在一周内收到一封包含你的证书的电子邮件。

使用探照灯api

Searchlight API包有两个主要功能:客户端和分析

  • client提供了一个围绕searchlight rest api的sdk,使您可以很容易地从您的帐户请求所需的数据。
  • 分析包括使用Searchlight API聚合数据(排名和搜索量)的函数

示例

客户
搜索灯光服务

SearchLightService客户端提供用于获取SearchLight和配置文件配置数据的包装器

from searchlight_api import client

# instantiate Searchlight client
ss = client.SearchlightService()
# Retrieve all Searchlight accounts you have access to.
# You can use this to retrieve Account IDs to instantiate the AccountService client

my_accounts = ss.get_accounts()
print(my_accounts)
[{'accountId': 'XXXX',
  'isActive': False,
  'name': 'Account 1',
  'webProperties': 'https://api.conductor.com/v3/accounts/XXXX/web-properties'},
 {'accountId': 'YYYY',
  'isActive': True,
  'name': 'Account 2',
  'webProperties': 'https://api.conductor.com/v3/accounts/YYYY/web-properties'}]

# Account IDs can also be found in Searchlight URLs: https://searchlight.conductor.com/YYYY/insight-stream

在searchlight中,关键字可以跨不同的排名源(或搜索引擎)、位置和设备进行跟踪。 您可以检索以下支持的内容:

rank_sources = ss.get_rank_sources()
locations = ss.get_locations()
devices = ss.get_devices()
会计服务

AccountService客户端提供从Searchlight帐户检索报告数据的功能,同时保留在SearchlightService客户端中找到的所有功能。实例化时需要searchlight帐户ID。

from searchlight_api import client
# instantiate the AccountService client
account_service = client.AccountService(YYYY)
# retrieve all web properties tracked in the account
web_properties = account_service.get_web_properties()

web_property_id = web_properties[0]['webPropertyId']

# the web_property_id can be used to get the name of the corresponding domain
domain_name = account_service.get_domain_name(web_property_id)

# use the web_property_id to get all tracked searches in the account
tracked_searches = account_service.get_tracked_searches(web_property_id)

# get a rank_source_id that the web_property is tracked against
rank_source_id = web_properties[0]['rankSourceInfo'][0]['rankSourceId']

# retrieve rank data for searches tracked against a web property and rank source for a given date within a reporting interval.
# by default the current date is used.
ranks = account_service.get_ranks(web_property_id, rank_source_id, date='2019-01-12')

# retrieve search volume data for searches tracked against a web property and rank source for a given date within a reporting interval.
# by default the current date is used.
search_volume = account_service.get_volume(web_property_id, rank_source_id, date='2019-01-12')
分析

通过分析,您可以使用AccountService客户端在给定日期内聚合整个帐户的报告数据

from searchlight_api.client import AccountService
from searchlight_api import analysis

account_service = AccountService(YYYY)

rank_data = analysis.rank_data(account_service, date='2019-01-12')
search_volume = analysis.search_volume(account_service)

要请求其他聚合方法,请访问dgoodman@conductor.compmurphy@conductor.com

与Searchlight API客户端一起使用熊猫
from searchlight_api import client, analysis
import pandas as pd

# instantiate AccountService object
account_service = client.AccountService(YYYY)

# get rank sources, locations and devices and turn to dfs
rank_source_df = pd.DataFrame(account_service.get_rank_sources())
location_df = pd.DataFrame(account_service.get_locations())
device_df = pd.DataFrame(account_service.get_devices())

# get the tracked searches and turn into a df
tracked_search_df = pd.DataFrame(analysis.all_tracked_searches(account_service))

# turn search_volume and rank_data to Data Frames
search_volume_df = pd.DataFrame(analysis.search_volume(account_service))
rank_data_df = pd.DataFrame(analysis.rank_data(account_service))

report = pd.merge(rank_data_df, search_volume_df, on=['trackedSearchId', 'rankSourceId', 'webPropertyId'])
report = report.merge(rank_source_df, on='rankSourceId', how='left')
print(report.head())
       itemType rankSourceId  standardRank target           targetDomainName  \
0    ANSWER_BOX            1           3.0                        example.com
1  IMAGE_RESULT            1           NaN                        example.com
2  LOCAL_RESULT            1           NaN         www.organiccompetitor.com
3  LOCAL_RESULT            1           NaN         www.organiccompetitor.com
4  LOCAL_RESULT            1           NaN         www.organiccompetitor.com
                                           targetUrl  targetWebPropetyId  \
0  https://www.example.com/subfolder1/             43162.0
1  https://www.example.com/subfolder2/...             43162.0
2  http://www.organiccompetitor.com/subfolder...                 NaN
3  http://www.organiccompetitor.com/subfolder/...                 NaN
4  http://www.organiccompetitor.com/subfolder/...                 NaN
   trackedSearchId  trueRank webPropertyId  averageVolume  \
0          7188291         6         43162         135000
1          7188291        62         43162         135000
2          7188291         4         43162         135000
3          7188291         2         43162         135000
4          7188291         3         43162         135000
                                         volumeItems  baseDomain  \
0  [{'volume': 165000, 'month': 11, 'year': 2018}...  google.com
1  [{'volume': 165000, 'month': 11, 'year': 2018}...  google.com
2  [{'volume': 165000, 'month': 11, 'year': 2018}...  google.com
3  [{'volume': 165000, 'month': 11, 'year': 2018}...  google.com
4  [{'volume': 165000, 'month': 11, 'year': 2018}...  google.com
             description          name deviceId  isActive locationId  \
0  Google (US / English)  GOOGLE_EN_US        1      True          1
1  Google (US / English)  GOOGLE_EN_US        1      True          1
2  Google (US / English)  GOOGLE_EN_US        1      True          1
3  Google (US / English)  GOOGLE_EN_US        1      True          1
4  Google (US / English)  GOOGLE_EN_US        1      True          1
             preferredUrl queryPhrase
0  http://www.example.com/     example phrase
1  http://www.example.com/     example phrase
2  http://www.example.com/     example phrase
3  http://www.example.com/     example phrase
4  http://www.example.com/     example phrase

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在设置AtomicBoolean之前检查另一个条件?   通过java将文件从windows计算机复制到另一台windows计算机   java如何在使用Cobertura时忽略与记录器相关的If条件?   java无法在Eclipse中导出Android应用程序   带GSON的java parse JSON返回null   java Extract/filter Splunk查询和条件逻辑   java ProgressBar带有一个倒计时器Android   java我应该为每个DAO编写通用方法的集成测试吗?   java从命令行访问执行JAR的文本文件   任务应用程序的java Gradle生成失败:processReleaseResources   预测函数的java DeepLearning4j NN不收敛   java如果发现特殊字符,如何删除字符串中的字符?   在Java中,从精确位置将字符串拆分为两个   将Java ByteArrayOutputStream压缩到不同的容器中   带有同心指示方块的java太空船模拟器制导计算机   java如何使用Jericho解析两条注释?   PersistenceUnit中的java多个类   连接到java中的elasticsearch?   当嵌入HTML页面时,删除java小程序中的外部白色边框   用于webstart的java CXF ClassCastException(SEIStub/ClientProxy)