当前位置: 首页>>代码示例>>Python>>正文


Python Socrata.upsert方法代码示例

本文整理汇总了Python中sodapy.Socrata.upsert方法的典型用法代码示例。如果您正苦于以下问题:Python Socrata.upsert方法的具体用法?Python Socrata.upsert怎么用?Python Socrata.upsert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sodapy.Socrata的用法示例。


在下文中一共展示了Socrata.upsert方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_upsert_exception

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import upsert [as 别名]
def test_upsert_exception():
    mock_adapter = {}
    mock_adapter["prefix"] = PREFIX
    adapter = requests_mock.Adapter()
    mock_adapter["adapter"] = adapter
    client = Socrata(DOMAIN, APPTOKEN, session_adapter=mock_adapter)

    response_data = "403_response_json.txt"
    setup_mock(adapter, "POST", response_data, 403, reason="Forbidden")

    data = [{"theme": "Surfing", "artist": "Wavves",
             "title": "King of the Beach", "year": "2010"}]
    try:
        client.upsert(DATASET_IDENTIFIER, data)
    except Exception as e:
        assert isinstance(e, requests.exceptions.HTTPError)
    else:
        raise AssertionError("No exception raised for bad request.")
开发者ID:Angiezhao,项目名称:sodapy,代码行数:20,代码来源:test_soda.py

示例2: test_upsert

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import upsert [as 别名]
def test_upsert():
    mock_adapter = {}
    mock_adapter["prefix"] = PREFIX
    adapter = requests_mock.Adapter()
    mock_adapter["adapter"] = adapter
    client = Socrata(DOMAIN, APPTOKEN, username=USERNAME, password=PASSWORD,
                     session_adapter=mock_adapter)

    response_data = "upsert_songs.txt"
    data = [{"theme": "Surfing", "artist": "Wavves",
             "title": "King of the Beach", "year": "2010"}]
    setup_mock(adapter, "POST", response_data, 200)
    response = client.upsert(DATASET_IDENTIFIER, data)

    assert isinstance(response, dict)
    assert response.get("Rows Created") == 1
    client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:19,代码来源:test_soda.py

示例3: test_upsert_exception

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import upsert [as 别名]
def test_upsert_exception():
    mock_adapter = {}
    mock_adapter["prefix"] = PREFIX
    adapter = requests_mock.Adapter()
    mock_adapter["adapter"] = adapter
    client = Socrata(DOMAIN, APPTOKEN, session_adapter=mock_adapter)

    path = "/songs.json"
    response_data = "403_response_json.txt"
    set_up_mock(adapter, "POST", response_data, 403, reason="Forbidden")

    data = [{"theme": "Surfing", "artist": "Wavves",
             "title": "King of the Beach", "year": "2010"}]
    try:
        response = client.upsert(PATH, data)
    except Exception, e:
        assert isinstance(e, requests.exceptions.HTTPError)
开发者ID:orio33,项目名称:sodapy,代码行数:19,代码来源:test_soda.py

示例4: open

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import upsert [as 别名]
    'bounce_rate',
    'entrance_rate',
    'exit_rate'
]

with open(os.path.join(report_folder, 'all-pages.json'), encoding='utf8') as json_file:
    data = json.load(json_file)
    taken_at = datetime.strptime(data['taken_at'], "%Y-%m-%dT%H:%M:%S.%fZ")
    datestamp = (taken_at - timedelta(days=1)).strftime('%Y-%m-%d')

    for page in data['data']:
        page = clean_ga_keys(page)
        visits = int(page.pop('visits'))

        page['date'] = datestamp
        page['id'] = datestamp + page['domain'] + page['page']
        page['pageviews'] = visits

        if visits > 0:
            page['bounce_rate'] = 100 * float(page['bounces']) / visits
            page['entrance_rate'] = 100 * float(page['entrances']) / visits
            page['exit_rate'] = 100 * float(page['exits']) / visits

        for key in percentages:
            page[key] = round(float(page.get(key, 0)), 2)

    upsert_chunks = [ data['data'][x:x+soda_batch_size] for x in range(0, len(data['data']), soda_batch_size) ]

    for chunk in upsert_chunks:
        soda_client.upsert(os.environ["SOCRATA_RESOURCEID"], chunk)
开发者ID:CityofSantaMonica,项目名称:analytics.smgov.net,代码行数:32,代码来源:job.py

示例5: open

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import upsert [as 别名]
import requests
from sodapy import Socrata
import json
# store api token in creds.txt
with open('creds.json', 'r') as f:
    creds = json.loads(f.read())
client = Socrata("odn.data.socrata.com", creds["token"], username=creds['username'], password=creds['password'])
data = requests.get('https://odn.data.socrata.com/resource/jwbj-xtgt.json?$where=region_name%20IS%20NOT%20NULL%20AND%20location%20IS%20NULL').json()
for row in data:
    if len(row['region_name'].split(',')) > 2:
        location = requests.get('http://nominatim.openstreetmap.org/search/?q=%s&format=json' % (row['region_name'])).json()
    else:
        location = requests.get('http://nominatim.openstreetmap.org/search/?q=%s,usa&format=json' % (row['region_name'])).json()
    if location:
        location = location[0]
        row['location'] = "(%s, %s)" % (location['lat'], location['lon'])
client.upsert("k53q-ytmx", data)
开发者ID:open-data-network,项目名称:utilities,代码行数:19,代码来源:geocode_domains.py


注:本文中的sodapy.Socrata.upsert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。