Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kip rework #15

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions read_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
from eth_account import Account
from web3.middleware import construct_sign_and_send_raw_middleware
import asyncio

from typing import Tuple

PRIVATE_KEY = os.getenv('PRIVATE_KEY')
CONTRACT_ADDRESS = '0xca733a39b72DA72078DBc1c642e6C3836C5b424E'
PROVIDER_HTTP_ENDPOINT = "http://54.153.142.251:8545"

def get_votes_from_blochchain(spec_hash):
def get_votes_from_blochchain(spec_hash: str) -> Tuple[int,int]:
"""For interacting with the smart contract and getting the current vote counts of a ballot

Args:
spec_hash (str): A unique sha256 hash of the ballot info

Returns:
Tuple[int,int]: (yes count, no count)
"""
w3 = Web3(Web3.HTTPProvider(PROVIDER_HTTP_ENDPOINT))
acct = Account.from_key(PRIVATE_KEY)
abi = json.load(open("voting.json"))

VotingAlpha = w3.eth.contract(address=CONTRACT_ADDRESS, abi=abi)

w3.middleware_onion.add(construct_sign_and_send_raw_middleware(acct.privateKey))
print(spec_hash)
p_id = VotingAlpha.functions.getProposalId(spec_hash.replace("0x0x","0x")).call()
proposalInfo = VotingAlpha.functions.getProposal(p_id).call()

print("No votes:", proposalInfo[3])
print("Yes votes:", proposalInfo[4])
return(proposalInfo[4], proposalInfo[3])
return(proposalInfo[4], proposalInfo[3])
43 changes: 26 additions & 17 deletions tag_topics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
from operator import itemgetter
from typing import Dict, List

# Topics
citizens = ["Education","Skills","Employment","Health", "Veterans", "youth","sports","Social","Indigenous","Disability"]
Expand All @@ -12,32 +13,40 @@
topics = {
"citizens":citizens,
"nature":nature,
"national_development":national_development,
"national development":national_development,
"borders":borders,
"economy":economy,
"communications":communications,
}

# related terms
rt = open("related_terms.csv","r")
topic_lines = rt.readlines()
headings = topic_lines.pop(0)
headings_list = headings.replace("\n","").lower().split(",")
def tag_bill(bill: Dict) -> List[str]:
"""To make tags for a bill based on the bill protfolio, title and text

topic_models = {}
for i in range(len(headings.replace("\n","").split(","))):
terms = []
for tl in topic_lines:
term = tl.replace("\n","").split(",")[i]
if term != "":
terms.append(term.lower())
topic_models[headings_list[i]] = terms
Args:
bill (Dict): A dict with the bill info. Need "short_title","summary". "portfolio" is preferred too

Returns:
List[str]: The tags
"""
# * get the related terms
rt = open("related_terms.csv","r")
topic_lines = rt.readlines()
headings = topic_lines.pop(0)
headings_list = headings.replace("\n","").lower().split(",")

topic_models = {}
for i in range(len(headings.replace("\n","").split(","))):
terms = []
for tl in topic_lines:
term = tl.replace("\n","").split(",")[i]
if term != "":
terms.append(term.lower())
topic_models[headings_list[i]] = terms

def tag_bill(bill):
t = []
if "portfolio" in bill.keys():
if bill["portfolio"] != "":
# * use portfolio to make the tags
portfoilo = bill["portfolio"]
for topic in topics.keys():
for domain in topics[topic]:
Expand All @@ -47,11 +56,11 @@ def tag_bill(bill):
if t != []:
return(t)
else:
# * use
p = []
for h in headings_list:
for rt in topic_models[h]:
if rt in bill["short_title"].lower() or rt in bill["summary"].lower():
if h not in p:
p.append(h)
return(p)

return(p)
26 changes: 8 additions & 18 deletions update_bills_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,17 @@
from tag_topics import tag_bill


# Connection String
client = pymongo.MongoClient(mongosettings[URL])
db = client[mongosettings[MONGODB]]
bills_collection = db[mongosettings[BILLSCOLLECTION]]


# dummy function, waiting for votes to be counted on the blockchain.
def get_votes(id):
return(500 + int(random.random()*1000), 500 + int(random.random()*1000))


naughty_words = ['corona', 'covid']
# print(all_bills)

bad_bills = []


def run(event, context):
# Connection String
client = pymongo.MongoClient(mongosettings[URL])
db = client[mongosettings[MONGODB]]
bills_collection = db[mongosettings[BILLSCOLLECTION]]
# ! this is a quick fix for the google ban on covid apps
naughty_words = ['corona', 'covid']
bad_bills = []
for i in range(len(all_bills)):
post = True
print(all_bills[i]["id"])
# print(all_bills[i]["id"])
url = all_bills[i]["url"]
bill = Bill(url)
# Standed keys
Expand Down