read_csv_files.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:AFSCbot 作者: HadManySons 项目源码 文件源码
def add_afsc_links(full_afsc_dict, reddit):
    """
    Add links to /r/AirForce wiki from given filename into the dictionary.
    :param dict: either enlisted_dict or officer_dict
    :param reddit: PRAW reddit object
    """
    # gets dict of AFSC to link on /r/AirForce wiki
    wiki_page = reddit.subreddit("AirForce").wiki["index"]
    wiki_soup = BeautifulSoup(wiki_page.content_html, "html.parser")
    links = wiki_soup.find_all("a")

    # currently all wiki AFSC are enlisted
    for link in links:
        # not all links have /r/AirForce/wiki/jobs so this is more generalized
        # using only /r/AirForce/ wiki links
        if "www.reddit.com/r/AirForce/wiki/" in link["href"]:
            AFSC_code = link["href"].split("/")[-1].upper()
            base_afsc = AFSC_code[:5]  # shaves off any prefixes
            if base_afsc in full_afsc_dict["enlisted"].keys():
                full_afsc_dict["enlisted"][base_afsc]["link"] = link["href"]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号