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


Python Socrata.close方法代码示例

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


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

示例1: test_set_permission

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_set_permission():
    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 = "empty.txt"
    setup_old_api_mock(adapter, "PUT", response_data, 200)

    # Test response
    response = client.set_permission(DATASET_IDENTIFIER, "public")
    assert response.status_code == 200

    # Test request
    request = adapter.request_history[0]
    query_string = request.url.split("?")[-1]
    params = query_string.split("&")

    assert len(params) == 2
    assert "method=setPermission" in params
    assert "value=public.read" in params

    client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:27,代码来源:test_soda.py

示例2: test_create

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_create():
    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 = "create_foobar.txt"
    setup_mock(adapter, "POST", response_data, 200, dataset_identifier=None)

    columns = [
        {"fieldName": "foo", "name": "Foo", "dataTypeName": "text"},
        {"fieldName": "bar", "name": "Bar", "dataTypeName": "number"}
    ]
    tags = ["foo", "bar"]
    response = client.create("Foo Bar", description="test dataset",
        columns=columns, tags=tags, row_identifier="bar")

    request = adapter.request_history[0]
    request_payload = json.loads(request.text) # can't figure out how to use .json

    # Test request payload
    for dataset_key in ["name", "description", "columns", "tags"]:
        assert dataset_key in request_payload

    for column_key in ["fieldName", "name", "dataTypeName"]:
        assert column_key in request_payload["columns"][0]

    # Test response
    assert isinstance(response, dict)
    assert len(response.get("id")) == 9
    client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:35,代码来源:test_soda.py

示例3: test_get

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

    response_data = "get_songs.txt"
    setup_mock(adapter, "GET", response_data, 200)
    response = client.get(DATASET_IDENTIFIER)

    assert isinstance(response, list)
    assert len(response) == 10

    client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:17,代码来源:test_soda.py

示例4: test_publish

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_publish():
    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 = "create_foobar.txt"
    setup_publish_mock(adapter, "POST", response_data, 200)

    response = client.publish(DATASET_IDENTIFIER)
    assert isinstance(response, dict)
    assert len(response.get("id")) == 9
    client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:17,代码来源:test_soda.py

示例5: test_get_metadata

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

    response_data = "get_song_metadata.txt"
    setup_old_api_mock(adapter, "GET", response_data, 200)
    response = client.get_metadata(DATASET_IDENTIFIER)

    assert isinstance(response, dict)
    assert "newBackend" in response
    assert "attachments" in response["metadata"]

    client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:18,代码来源:test_soda.py

示例6: test_publish

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_publish():
    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 = "create_foobar.txt"
    resource = "/api/views/songs/publication.json" # publish() removes .json
    set_up_mock(adapter, "POST", response_data, 200, resource=resource)
    
    response = client.publish("/resource/songs.json") # hard-coded so request uri is matched
    assert isinstance(response, dict)
    assert len(response.get("id")) == 9
    client.close()
开发者ID:orio33,项目名称:sodapy,代码行数:18,代码来源:test_soda.py

示例7: test_upsert

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [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

示例8: test_delete

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_delete():
    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)

    uri = "{0}{1}/api/views/{2}.json".format(PREFIX, DOMAIN, DATASET_IDENTIFIER)
    adapter.register_uri("DELETE", uri, status_code=200)
    response = client.delete(DATASET_IDENTIFIER)
    assert response.status_code == 200

    try:
        client.delete("foobar")
    except Exception as e:
        assert isinstance(e, requests_mock.exceptions.NoMockAddress)
    finally:
        client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:21,代码来源:test_soda.py

示例9: test_upsert_exception

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [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.")
    finally:
        client.close()
开发者ID:HTrammel,项目名称:sodapy,代码行数:22,代码来源:test_soda.py

示例10: test_replace

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_replace():
    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 = "replace_songs.txt"
    data = [
        {"theme": "Surfing", "artist": "Wavves", "title": "King of the Beach",
         "year": "2010"},
        {"theme": "History", "artist": "Best Friends Forever",
         "title": "Abe Lincoln", "year": "2008"},
    ]
    setup_mock(adapter, "PUT", response_data, 200)
    response = client.replace(DATASET_IDENTIFIER, data)

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

示例11: test_set_permission

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_set_permission():
    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 = "empty.txt"
    resource = "/api/views" + PATH
    set_up_mock(adapter, "PUT", response_data, 200, resource=resource)
    
    # Test response
    response = client.set_permission(PATH, "public")
    assert response.status_code == 200
    
    # Test request
    request = adapter.request_history[0]
    qs = request.url.split("?")[-1]
    assert qs == "method=setPermission&value=public.read"
    client.close()
开发者ID:orio33,项目名称:sodapy,代码行数:23,代码来源:test_soda.py

示例12: test_replace_non_data_file

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_replace_non_data_file():
    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 = "successblobres.txt"
    nondatasetfile_path = 'tests/test_data/nondatasetfile.zip'

    setup_replace_non_data_file(adapter, "POST", response_data, 200)

    with open(nondatasetfile_path, 'rb') as fin:
        file = (
            {'file': ("nondatasetfile.zip", fin)}
        )
        response = client.replace_non_data_file(DATASET_IDENTIFIER, {}, file)

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

示例13: test_client

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
def test_client():
    client = Socrata(DOMAIN, APPTOKEN)
    assert isinstance(client, Socrata)
    client.close()
开发者ID:Angiezhao,项目名称:sodapy,代码行数:6,代码来源:test_soda.py

示例14: Socrata

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
theft = client.get("cuks-n6tp", select ="category,time,location", where ="category='VEHICLE THEFT'",limit=10)
print "vehicle theft data"
print theft
vandalism = client.get("cuks-n6tp", select ="category,time,location", where ="category='VANDALISM'",limit=10)
print "VANDALISM data"
print vandalism
kidnapping = client.get("cuks-n6tp", select ="category,time,location", where ="category='KIDNAPPING'",limit=10)
print "KIDNAPPING data"
print kidnapping
sex = client.get("cuks-n6tp", select ="category,time,location", where ="category='SEX OFFENSES, FORCIBLE'",limit=10)
print "SEX OFFENSES, FORCIBLE data"
print sex
dui = client.get("cuks-n6tp", select ="category,time,location", where ="category='DRIVING UNDER THE INFLUENCE'",limit=10)
print "DUI data"
print dui
client.close()

# search radius
# https://data.sfgov.org/resource/cuks-n6tp.json?$where=within_circle(location,%2037.78,%20-122.41,%201000)

# https://data.cms.gov/resource/97k6-zzx3.json?$limit=5
# client = Socrata("https://data.cms.gov/resource/", None)
# print client.get("http://data.cms.gov/resource/97k6-zzx3.json?$order=average_covered_charges$limit=1", limit=2)

# app token - need it eventually
# https://data.seattle.gov/resource/3k2p-39jp.json?$$app_token=APP_TOKEN
# https://dev.socrata.com/docs/app-tokens.html
# 8gffbg1meMZ1e2Z0yOz2OpwZq
# secret token at https://data.sfgov.org/profile/alex-wap/7wfp-cp8m/app_tokens
'''
SF DATA FORMAT
开发者ID:alex-wap,项目名称:CodingDojo,代码行数:33,代码来源:soda.py

示例15: get

# 需要导入模块: from sodapy import Socrata [as 别名]
# 或者: from sodapy.Socrata import close [as 别名]
 def get(self, request, *args, **kwargs):
     ''' Get criminal records from the dataset and save them the database as CriminalRecord objects'''
     ids = CriminalRecord.objects.values_list('case_id', flat=True)
     domain = settings.SOCRATA_DOMAIN
     token = settings.SOCRATA_APP_TOKEN
     endpoint = settings.SOCRATA_DATASET_ENDPOINT
     client = Socrata(domain, token)
     order = "date"
     where = 'latitude IS NOT NULL'
     offset = 0
     limit = 1000
     status = 200
     try:
         data = client.get(
             endpoint, order=order, where=where,
             offset=offset, limit=limit)
         while data:
             for record in data:
                 if self.to_int(record.get('id')) not in ids:
                     attrs = {
                         'case_id': self.to_int(
                             self.get_from_dict(record, 'id')),
                         'case_number': self.get_from_dict(
                             record, 'case_number'),
                         'date': datetime.strptime(
                             self.get_from_dict(record, 'date'),
                             '%Y-%m-%dT%H:%M:%S'),
                         'block': self.get_from_dict(record, 'block'),
                         'iucr': self.get_from_dict(record, 'iucr'),
                         'primary_type': self.get_from_dict(
                             record, 'primary_type'),
                         'crime_description': self.get_from_dict(
                             record, 'description'),
                         'location_description': self.get_from_dict(
                             record, 'location_description'),
                         'has_arrested': self.get_from_dict(
                             record, 'arrest'),
                         'is_domestic': self.get_from_dict(
                             record, 'domestic'),
                         'beat': self.get_from_dict(record, 'beat'),
                         'district': self.get_from_dict(
                             record, 'district'),
                         'ward': self.to_int(
                             self.get_from_dict(record, 'ward')),
                         'community_area': self.get_from_dict(
                             record, 'community_area'),
                         'fbi_code': self.get_from_dict(
                             record, 'fbi_code'),
                         'x_coordinate': self.to_int(
                             self.get_from_dict(
                                 record, 'x_coordinate')),
                         'y_coordinate': self.to_int(
                             self.get_from_dict(
                                 record, 'y_coordinate')),
                         'year': self.to_int(
                             self.get_from_dict(record, 'year')),
                         'updated_on': datetime.strptime(
                             self.get_from_dict(record, 'updated_on'),
                             '%Y-%m-%dT%H:%M:%S'),
                         'latitude': float(self.get_from_dict(
                             record, 'latitude')),
                         'longitude': float(self.get_from_dict(
                             record, 'longitude')),
                         'location': Point(
                             float(self.get_from_dict(
                                 record, 'longitude')),
                             float(self.get_from_dict(
                                 record, 'latitude')))
                     }
                     CriminalRecord.objects.create(**attrs)
             offset += limit
             data = client.get(
                 endpoint, order=order, where=where,
                 offset=offset, limit=limit)
         client.close()
     except Exception, e:
         print e
         status = 400
开发者ID:jayArnel,项目名称:crimemapping,代码行数:80,代码来源:views.py


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