コード例 #1
0
ファイル: kdconfig.py プロジェクト: bkdwei/kdMarkdownPad
def update_conf(cur_file):
    check_and_create(config_file)
    with open(config_file, "w+") as f:
        conf = {}
        conf["cur_file"] = cur_file
        f.write(json.dumps(conf))
        f.flush()
コード例 #2
0
ファイル: kdconfig.py プロジェクト: bkdwei/kdmongoviewer
def init_conf():
    check_and_create(config_file)
    with open(config_file, "r") as f:
        content = f.read()
        if content.strip() != "":
            conf = json.loads(content)
            return conf
コード例 #3
0
ファイル: kdconfig.py プロジェクト: bkdwei/kdmongoviewer
def update_conf(host, port):
    check_and_create(config_file)
    with open(config_file, "w+") as f:
        conf = {}
        conf["host"] = host
        conf["port"] = port
        f.write(json.dumps(conf))
        f.flush()
コード例 #4
0
ファイル: kdconfig.py プロジェクト: charles2268/kdssh
 def init_confs(self):
     check_and_create(self.config_file)
     with open(self.config_file, "r") as f:
         content = f.read()
         if content.strip() != "":
             json_content = json.loads(content)
             self.confs = json_content
         else:
             self.confs = []
コード例 #5
0
ファイル: backup_blog.py プロジェクト: bkdwei/kd163blogBackUp
 def run(self):
     try:
         # ~ if self.continue_on_failure is not True:
         self.down_blog_source()
         self.convert_to_html_file()
         self.show_status_signal.emit("备份随笔结束")
     except:
         if self.continue_on_failure:
             fileutil.check_and_create(self.backup_dir + "config.json")
             with open(self.backup_dir + "config.json", "r") as f:
                 f.write(str(self.continue_index))
         print(sys.exc_info())
         self.show_status_signal.emit("系统异常:" + str(sys.exc_info()[1]) +
                                      "\n下载失败")
コード例 #6
0
 def init_conf(self):
     check_and_create(self.config_path)
     with open(self.config_path, "r") as f:
         content = f.read().strip()
         # ~ print("content:" + content)
         if content != "":
             conf = json.loads(content)
             self.le_username.setText(conf["username"])
             self.le_email.setText(conf["email"])
             # ~ self.le_project.setText(conf["project"])
             self.conf = conf
             self.path = conf["path"]
         else:
             self.conf = None
コード例 #7
0
 def on_buttonBox_accepted(self):
     conf = {}
     conf["username"] = self.le_username.text()
     conf["email"] = self.le_email.text()
     # ~ conf["project"] = self.le_project.text()
     conf["path"] = self.path
     check_and_create(self.config_path)
     check_and_create_dir(self.path)
     with open(self.config_path, "w+") as f:
         f.write(json.dumps(conf))
         os.chdir(self.path)
         self.exec_cmd(
             "cd {};git config --global user.name {};git config --global user.email {}"
             .format(self.path, conf["username"], conf["email"]))
         self.show_result("$ 设置帐号信息成功")
     self.conf = conf
コード例 #8
0
    def convert_to_html_file(self):
        with open(self.backup_dir + self.mood_file, "r") as f:
            str1 = f.read().strip()
            field_content = {}
            field_content["name"] = "content"
            field_content["pattern"] = r'(?<=content=").+?(?=";)'
            field_publishTime = {}
            field_publishTime["name"] = "publishTime"
            field_publishTime["pattern"] = r"(?<=publishTime=).+?(?=;)"
            field_commentCount = {}
            field_commentCount["name"] = "commentCount"
            field_commentCount["pattern"] = r"(?<=commentCount=).+?(?=;)"
            field_id = {}
            field_id["name"] = "id"
            field_id["pattern"] = r'(?<=id=").+?(?=";)'
            fields = [field_content, field_publishTime, field_commentCount, field_id]

            items = self.analyze_response(str1, fields)
            print("心情随笔:", items)

        html_content = "<html><meta charset='utf-8'><body>"
        items_count = len(items)
        for i, item in enumerate(items):
            self.show_status_signal.emit("进度:" + str(i + 1) + "/" + str(items_count))
            commentCount = item["commentCount"]
            html_content = (
                html_content
                + "<div class='item'><div class='content'>"
                + item["content"]
                + "</div><div class='publishTime'>"
                + item["publishTime"]
                + ",评论("
                + commentCount
                + ")</div><hr></div>"
            )
            if commentCount != "0":
                self.show_status_signal.emit(
                    "正在获取第{}条心情随笔的{}条评论".format(i + 1, commentCount)
                )
                comment_items = self.get_commet(item["id"], item["commentCount"])
                html_content += self.append_comment(comment_items)
        html_content += "</body></html>"

        fileutil.check_and_create(self.backup_dir + self.mood_html_file)
        with open(self.backup_dir + self.mood_html_file, "w+") as f2:
            f2.write(html_content)
        print("保存html格式的心情随笔成功", html_content)
コード例 #9
0
 def get_userspace_url(self):
     album_catelog_url = "http://photo.163.com/photo/{}/dwr/call/plaincall/UserSpaceBean.getUserSpace.dwr?u={}".format(
         self.blog_name, self.blog_name
     )
     self.post_userspace_data["c0-param0"] = self.blog_name
     r = requests.post(
         album_catelog_url, data=self.post_userspace_data, headers=self.headers
     )
     fileutil.check_and_create(self.backup_dir + self.album_file)
     with open(self.backup_dir + self.album_catelog_file, "w+") as f:
         f.write(r.text)
         self.show_status_signal.emit("下载心情随笔的原始数据成功\n开始解析原始数据")
         self.albumCount = re.search(r"(?<=albumCount:).+?(?=,)", r.text)[0]
         self.photoCount = re.search(r"(?<=photoCount:).+?(?=,)", r.text)[0]
         self.userId = re.search(r"(?<=userId:).+?(?=,)", r.text)[0]
         self.usedSpace = re.search(r"(?<=usedSpace:).+?(?=,)", r.text)[0]
         self.cacheFileUrl = re.search(r'(?<=cacheFileUrl:").+?(?=",)', r.text)[0]
         print(self)
コード例 #10
0
ファイル: backup_blog.py プロジェクト: bkdwei/kd163blogBackUp
    def down_blog_source(self):
        self.show_status_signal.emit("开始下载{}条日志".format(self.blog_count))

        get_blog_url = "http://api.blog.163.com/{}/dwr/call/plaincall/BlogBeanNew.getBlogsNewTheme.dwr".format(
            self.blog_name)
        self.post_blog_data["c0-param0"] = self.user_id
        self.post_blog_data["c0-param2"] = self.blog_count

        fileutil.check_and_create(self.backup_dir + self.blog_source_file)
        print("get_blog_url:{},post_blog_data:{}".format(
            get_blog_url, self.post_blog_data))
        r = requests.post(get_blog_url,
                          data=self.post_blog_data,
                          headers=self.headers)
        # ~ print(r.text)

        with open(self.backup_dir + self.blog_source_file, "w+") as f:
            f.write(r.text)
            self.show_status_signal.emit("下载日志的原始数据成功\n开始解析原始数据")
コード例 #11
0
    def down_mood_source(self):
        self.show_status_signal.emit("开始下载{}条心情随笔".format(self.mood_count))

        get_mood_url = "http://api.blog.163.com/{}/dwr/call/plaincall/FeelingsBeanNew.getRecentFeelingCards.dwr".format(
            self.blog_name
        )
        self.post_mood_data["c0-param0"] = self.user_id
        self.post_mood_data["c0-param2"] = self.mood_count
        print(
            "get_mood_url:{},self.post_mood_data:{}".format(
                get_mood_url, self.post_mood_data
            )
        )
        r = requests.post(get_mood_url, data=self.post_mood_data, headers=self.headers)
        # ~ print(r.text)

        fileutil.check_and_create(self.backup_dir + self.mood_file)
        with open(self.backup_dir + self.mood_file, "w+") as f:
            f.write(r.text)
            self.show_status_signal.emit("下载心情随笔的原始数据成功\n开始解析原始数据")
コード例 #12
0
ファイル: backup_blog.py プロジェクト: bkdwei/kd163blogBackUp
    def __init__(self, backup_dir, blog_name, user_id, blog_count,
                 continue_on_failure):
        super().__init__()
        self.blog_source_file = "日志/source_blog.txt"
        self.blog_html_file = "日志/blog.html"

        self.backup_dir = backup_dir
        self.blog_name = blog_name
        self.user_id = user_id
        self.blog_count = blog_count
        self.continue_on_failure = continue_on_failure
        self.continue_index = 0
        if continue_on_failure:
            fileutil.check_and_create(backup_dir + "config.json")
            with open(backup_dir + "config.json", "r") as f:
                index_content = f.read().strip()
                if f.read().strip():
                    self.continue_index = int(index_content)

        self.post_blog_data = {
            "callCount": "1",
            "scriptSessionId": "187",
            "c0-scriptName": "BlogBeanNew",
            "c0-methodName": "getBlogsNewTheme",
            "c0-id": "0",
            # ~ "c0-param0": "",
            "c0-param1": "0",
            "c0-param2": "1",
            "batchId": "159937",
        }
        self.headers = {
            "contents-Type":
            "text/plain",
            "Referer":
            "http://api.blog.163.com/crossdomain.html?publish_time=20100205",
            "User-Agent":
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36",
        }
コード例 #13
0
ファイル: backup_blog.py プロジェクト: bkdwei/kd163blogBackUp
    def convert_to_html_file(self):
        fileutil.check_and_create(self.backup_dir + self.blog_html_file)
        with open(self.backup_dir + self.blog_source_file, "r") as f:
            str1 = f.read().strip()
            field_title = {}
            field_title["name"] = "title"
            field_title["pattern"] = r'(?<=title=").+?(?=";)'
            field_link = {}
            field_link["name"] = "link"
            field_link["pattern"] = r'(?<=permalink=").+?(?=";)'
            field_publishTime = {}
            field_publishTime["name"] = "publishTime"
            field_publishTime["pattern"] = r"(?<=publishTime=).+?(?=;)"
            field_accessCount = {}
            field_accessCount["name"] = "accessCount"
            field_accessCount["pattern"] = r"(?<=accessCount=).+?(?=;)"
            field_commentCount = {}
            field_commentCount["name"] = "commentCount"
            field_commentCount["pattern"] = r"(?<=commentCount=).+?(?=;)"
            field_id = {}
            field_id["name"] = "id"
            field_id["pattern"] = r'(?<=id=").+?(?=";)'
            fields = [
                field_title,
                field_link,
                field_publishTime,
                field_accessCount,
                field_commentCount,
                field_id,
            ]

            items = self.analyze_response(str1, fields)
            print("日志数量:{},日志内容:{}".format(len(items), items))

        html_content = "<html><meta charset='utf-8'><body>"
        items_count = len(items)
        for i, item in enumerate(items, self.continue_index - 1):
            self.continue_index = i
            self.show_status_signal.emit("进度:{}/{},{}".format(
                i + 1, items_count, item["title"]))
            commentCount = item["commentCount"]
            html_content = (
                html_content +
                "<div class='item'><div class='title'>{}</div><div class='publishTime'>{},评论({})</div><div class='link'>{}</div><hr></div>"
                .format(item["title"], item["publishTime"], commentCount,
                        item["link"]))
            try:
                self.get_single_blog(item, i + 1)
            except:
                self.show_status_signal.emit("系统异常:" + str(sys.exc_info()[1]) +
                                             "\n下载失败")
            # ~ if commentCount != "0":
            # ~ self.show_status_signal.emit(
            # ~ "正在获取第{}条日志的{}条评论".format(i + 1, commentCount)
            # ~ )
            # ~ comment_items = get_commet(self.blog_name,item["id"],item["commentCount"],html_content)
            # ~ html_content = append_comment(html_content,comment_items)
        html_content += "</body></html>"

        fileutil.check_and_create(self.backup_dir + self.blog_html_file)
        with open(self.backup_dir + self.blog_html_file, "w+") as f2:
            f2.write(html_content)
        print("保存html格式的日志成功")