Code Snippets¶
Introduction¶
Here, you can find some code snippets to help you use wikirate4py successfully. Contributions enhancing this section are more than welcome!
Get Verified Answers¶
# returns all answers of Company Report Available metric that were added by a steward
answers = api.get_answers(metric_name='Company Report Available',
metric_designer='Core',
verification='steward_added',
year=2019)
Get Relationships¶
# returns all supplier of relationships where the suppliers is located in the United Kingdom
answers = self.api.get_relationships(metric_name='Supplier of',
metric_designer='Commons',
country='United Kingdom')
Add Company¶
company = self.api.add_company(name='A Company',
headquarters='United Kingdom',
os_id='OAR_ID_123')
Delete Company¶
#delete a company given it's numerical identifier
self.api.delete_company(123)
Add Source¶
source = self.api.add_source(url='https://en.wikipedia.org/wiki/Target_Corporation',
title='wikipedia page of Target Corporation 2021',
company='Target',
comment='07/07/2021 This is a comment',
year=2020)
Update Source¶
source = self.api.update_source(name='Source-000106092',
year=2021)
Add Answer¶
answer = self.api.add_answer(metric_name='Company Report Available',
metric_designer='Core',
value='No',
year=2021,
source='Source_000104408',
company='BORA 2 LTD',
comment='This is a test import of a metric answer')
Update Answer¶
answer = self.api.update_answer(metric_name='Company Report Available',
metric_designer='Core',
year=2021,
company='BORA 2 LTD',
source='Source_000104409')
Update Answer By ID¶
An answer can be identified either by its cardname comprised of matric_designer+metric_name+company+year either from its numerical identifier. If you want to update the company/year of a specific answer you need to provide its numerical identifier as highlighted below:
answer = self.api.update_answer(identifier=1234,
year=2024)
Add Relationship¶
relationship = self.api.add_relationship(metric_name='Supplied by',
metric_designer='Commons',
year=2021,
value='Tier 1 Supplier',
source='Source-000106091',
subject_company=7217,
object_company=7457810)
Update Relationship¶
relationship = self.api.update_relationship(metric_name='Supplied by',
metric_designer='Commons',
year=2021,
value='Tier 2 Supplier',
subject_company=7217,
object_company=7457810,
comment='This a relationship answer')
Update Relationship by ID¶
A relationship can be identified either by its cardname, comprised of matric_designer+metric_name+subject_company+object_company+year either from its numerical identifier. If you want to update the subject_company/object_company/year of a specific relationship you need to provide its numerical identifier as highlighted below:
relationship = self.api.update_relationship(identifier=123586,
subject_company=5485369)