示例#1
0
def update_last_term():
    query = Legislator.select(
        Legislator.name,
        fn.max(Legislator.term).alias("last_term")).group_by(Legislator.name)
    for legislator in query:
        Candidate.update(lastTerm=legislator.last_term).where(
            Candidate.name == legislator.name).execute()
示例#2
0
def write_result_to_db(file_path):
    with open(file_path) as fp:
        data = json.load(fp)

    for candidate in data:
        Candidate.update(dateOfBirth=candidate["date_of_birth"], age=candidate["age"]).where(
            Candidate.name == candidate["page_name"]
        ).execute()
示例#3
0
def update_candidate(candidate_data):
    for candidate in candidate_data:
        try:
            Candidate.update(
                wikidataPicUrl=candidate["picUrl"],
                wikidataDateOfBirth=candidate["dateOfBirth"]).where(
                    Candidate.name == candidate["name"]).execute()
        except DataError as e:
            print(f'Error on candidate: {candidate["name"]}')
            print(e)
示例#4
0
def update_photo():
    latest_id = Legislator.select(Legislator.id).group_by(
        Legislator.name).order_by(Legislator.term.desc())
    query = Legislator.select(Legislator.name, Legislator.term,
                              Legislator.picUrl).where(
                                  Legislator.id.in_(latest_id))

    for legislator in query:
        Candidate.update(picUrl=legislator.picUrl).where(
            Candidate.name == legislator.name,
            Candidate.lastTerm == legislator.term).execute()
示例#5
0
def tag_history_candidate():
    query = Legislator.select(Legislator.name)
    names = [re.match(r"[\u4e00-\u9fff|.]{2,}", row.name)[0] for row in query]
    print(f"history legislators: {names}")
    query = Candidate.update(historyLegislator=True).where(
        Candidate.name.in_(names))
    query.execute()
示例#6
0
def tag_current_legislator_in_db(names: List[str]) -> None:
    """Write current_legislator column.

    Notice: won't change others to False
    """
    print(f"current legislators: {names}")
    query = Candidate.update(currentLegislator=True).where(Candidate.name.in_(names))
    query.execute()
示例#7
0
def tag_current_candidate():
    query = Legislator.select(Legislator.name).where(
        Legislator.term == "09", Legislator.leaveFlag == "否")
    names = [re.match(r"[\u4e00-\u9fff|.]{2,}", row.name)[0] for row in query]
    print(f"current legislators: {names}")
    query = Candidate.update(currentLegislator=True).where(
        Candidate.name.in_(names))
    query.execute()