├── LICENSE ├── README.md ├── abi └── kudos.json ├── kudos └── __init__.py ├── requirements.txt └── scripts └── list_kudos.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Open Kudos 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kudos Python 2 | 3 | Kudos Python is an scraping kudos library based on the [kudos contract](https://github.com/gitcoinco/Kudos721Contract). 4 | To begin to scrap kudos see [Setup](#Setup) 5 | 6 | 7 | ## Setup 8 | This library depends on the packages `web3` and `requests` as mandatory dependencies to work and some other dependencies to pimp the script output. 9 | 10 | So to install dependencies yo need to execute this: 11 | 12 | ``` 13 | $ pip install -r requirements.txt 14 | ``` 15 | 16 | Also is required by the script the ABI of the kudos contract to know how to intereract and retrieve the list of kudos. 17 | So if you don't have the ABI kudos contract, you can build it with the following commands: 18 | 19 | ``` 20 | # Get the kudos source code 21 | $ git clone https://github.com/gitcoinco/Kudos721Contract.git 22 | $ cd Kudos721Contract 23 | # Install dependencies 24 | $ npm install -g truffle ganache-cli 25 | $ npm install 26 | # Compile contracts to get the ABI 27 | $ truffle compile 28 | ``` 29 | 30 | ## RUN 31 | 32 | Now we need set some env varibles to indicate to the script where its located the build contract, the endpoint to connect to some eth instance and limit the displayed kudos if its neccesary. Note that this env variables are required only by the script and not by the kudos module, where you pass this info as parameter. 33 | 34 | 35 | ```sh 36 | $ export CONTRACT_JSON_PATH='abi/Kudos.json' 37 | $ export NETWORK_URL='https://mainnet.infura.io/v3/...' 38 | $ export LIMIT_KUDOS=15 39 | ``` 40 | 41 | Now it's time to get some kudos, only you need run the following command and you're done! 42 | 43 | ```sh 44 | $ python scripts/list_kudos.py 45 | Processing |################################| 15/15 46 | id name description art url 47 | ---- ------------------------- ----------------------- --------------------------------- 48 | 13 Ruby Gem Is there anyone who ... https://s.gitcoin.co/static/v2... 49 | 14 Angular Royalty AngularJS is a great... https://s.gitcoin.co/static/v2... 50 | 12 Unix Philosophy Owners of this badge... https://s.gitcoin.co/static/v2... 51 | 4 Gitcoin Genesis The Gitcoin Genesis ... https://s.gitcoin.co/static/v2... 52 | 8 Do More Faster Is there anything be... https://s.gitcoin.co/static/v2... 53 | 10 Elixer Mixer Elixer Mixers are kn... https://s.gitcoin.co/static/v2... 54 | ... 55 | ``` 56 | ## See also 57 | 58 | - [kudosbadges Repo](https://github.com/gitcoinco/kudosbadges) 59 | - [kudos python client](https://github.com/OpenKudos/python_client) 60 | - [kudos contract Repo](https://github.com/gitcoinco/Kudos721Contract) 61 | 62 | 63 | ## License 64 | 65 | See [LICENSE](LICENSE). 66 | -------------------------------------------------------------------------------- /kudos/__init__.py: -------------------------------------------------------------------------------- 1 | import json 2 | import web3 as w3 3 | import requests 4 | 5 | 6 | __all__ = ['KudosContract', 'Kudos'] 7 | 8 | class KudosContract: 9 | def __init__(self, network, address, abi): 10 | self.w3 = w3.Web3(w3.HTTPProvider(network)) 11 | self.contract = self.w3.eth.contract(address=address, abi=abi) 12 | self.last_id = self.contract.functions.getLatestId().call() 13 | 14 | def get_by_id(self, kudos_id): 15 | return self.contract.functions.getKudosById(kudos_id).call() 16 | 17 | def get_token_uri(self, kudos_id): 18 | return self.contract.functions.tokenURI(kudos_id).call() 19 | 20 | def __iter__(self): 21 | self.step = 1 22 | return self 23 | 24 | def __next__(self): 25 | if self.step <= self.last_id: 26 | token_uri = self.get_token_uri(self.step) 27 | r = requests.get(token_uri) 28 | self.step += 1 29 | return Kudos(self.step, r.json()) 30 | else: 31 | raise StopIteration 32 | 33 | 34 | class Kudos: 35 | def __init__(self, kudos_id, data): 36 | self.attributes = data.get('attributes', []) 37 | self.background_color = data.get('background_color', '') 38 | self.description = data.get('description', '') 39 | self.external_url = data.get('external_url', '') 40 | self.image_url = data.get('image', '') 41 | self.name = data.get('name', '') 42 | 43 | self.id = kudos_id 44 | 45 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | web3==4.8.2 2 | requests==2.21.0 3 | tabulate==0.8.3 4 | progress==1.4 5 | -------------------------------------------------------------------------------- /scripts/list_kudos.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.insert(0, '../kudos') 3 | 4 | import kudos 5 | import json 6 | import os 7 | import time 8 | 9 | from tabulate import tabulate 10 | from progress.bar import Bar 11 | 12 | 13 | contract_path = os.getenv('CONTRACT_JSON_PATH') 14 | network = os.getenv('NETWORK_URL') 15 | 16 | address = os.getenv('ADDRESS_NETWORK', '0x2aEa4Add166EBf38b63d09a75dE1a7b94Aa24163') 17 | limit = int(os.getenv('LIMIT_KUDOS', 10)) 18 | 19 | if __name__ == '__main__': 20 | 21 | kudos_set = set() 22 | with open(contract_path) as contract_file: 23 | json_contract = json.load(contract_file) 24 | kudos_contract = kudos.KudosContract(network, 25 | address=address, 26 | abi=json_contract['abi']) 27 | 28 | if limit > kudos_contract.last_id: 29 | limit = kudos_contract.last_id 30 | 31 | bar = Bar('Processing', max=limit) 32 | 33 | for kudos in kudos_contract: 34 | kudos_set.add((kudos.id, kudos.name, kudos.description[:20] + '...', kudos.image_url[:30] + '...')) 35 | 36 | bar.next() 37 | 38 | if kudos.id > limit: 39 | break 40 | 41 | bar.finish() 42 | 43 | print(tabulate(kudos_set, headers=['id', 'name', 'description', 'art url'])) 44 | 45 | --------------------------------------------------------------------------------