This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import matplotlib.pyplot as plt | |
from imageio import imread | |
from wordcloud import WordCloud | |
# font type | |
base_path = os.getcwd() | |
font_path = base_path + '/fonts/SourceHanSerif/SourceHanSerifK-Light.otf' | |
# backgroud image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from pyhanlp import * | |
words_count_dict = {} | |
skip_word_pat = re.compile("文章|https|http|html|JPTT|bbs|標題|ptt|女孩|八卦|版|WomenTalk|批踢踢") | |
def _segment(source): | |
for term in HanLP.segment(source): | |
pos = term.nature.__str__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import requests | |
from bs4 import BeautifulSoup as bs | |
from requests.adapters import HTTPAdapter | |
from concurrent.futures import ThreadPoolExecutor | |
def fetch(session, url): | |
with session.get(url) as response: | |
src_html = response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_hotlist_article_urls(): | |
hotlist_url = "https://moptt.azurewebsites.net/api/v2/hotpost?b=Gossiping&b=Boy-Girl&b=Beauty&b=marvel&b=WomenTalk&b=movie&page=%257B%2522skip%2522%253A0%257D" | |
headers = {"cookie": "over18=1;", "Authorization": "cMIS1Icr95gnR2U19hxO2K7r6mYQ96vp"} | |
resp = requests.get(hotlist_url, headers=headers) | |
res_json = resp.json()["posts"] | |
article_urls = [r["url"] for r in res_json] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass, asdict | |
import datetime | |
@dataclass | |
class AccountRecord: | |
consumption: int | |
event: str | |
date: datetime.datetime | |
today = datetime.datetime.now() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cached_property import cached_property | |
class Monopoly(object): | |
def __init__(self): | |
self.boardwalk_price = 500 | |
@cached_property | |
def boardwalk(self): | |
# Again, this is a silly example. Don't worry about it, this is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cached_property import cached_property | |
class Monopoly(object): | |
def __init__(self): | |
self.boardwalk_price = 500 | |
@cached_property | |
def boardwalk(self): | |
# using example from cached_property pypi document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pokemon(object): | |
def __init__(self, name, skill, level): | |
self.name = name | |
self.skill = skill | |
self.level = level | |
@property | |
def attack_power(self): | |
return self.level * 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Investment(object): | |
def __init__(self, us_dollar, fund, stock): | |
self.us_dollar = us_dollar | |
self.fund = fund | |
self.stock = stock | |
# convert unit: transfer us_dollar to RMB | |
@staticmethod | |
def convert_unit(us_dollar): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
class User(object): | |
bar = 1 | |
def __init__(self, name, age, height): | |
self.name = name | |
self.age = age | |
self.height = height | |
# this function didnt use other class property |
NewerOlder