Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f77c6e

Browse files
committed
新增:make_content脚本
1 parent 9e727c8 commit 3f77c6e

File tree

6 files changed

+134
-7
lines changed

6 files changed

+134
-7
lines changed

script/README.md renamed to script/github_bot/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Github Bot
2-
>兴趣是最好的老师,[HelloGithub](https://github.com/521xueweihan/HelloGithub)就是帮你找到兴趣!
1+
# GitHub Bot
2+
>兴趣是最好的老师,[HelloGitHub](https://github.com/521xueweihan/HelloGitHub)就是帮你找到兴趣!
33
4-
![](https://github.com/521xueweihan/HelloGithub/blob/master/01/img/hello-github.jpg)
5-
6-
这个脚本主要使用收集Github上优秀的项目,用于编写[《HelloGithub月刊》](https://github.com/521xueweihan/HelloGithub),后面还会持续开发~
4+
![](https://github.com/521xueweihan/HelloGitHub/blob/master/01/img/hello-github.jpg)
75

86
## 运行步骤
7+
这个脚本主要使用收集GitHub上优秀的项目,用于编写[《HelloGitHub月刊》](https://github.com/521xueweihan/HelloGitHub),后面还会持续开发~
8+
99
1. 安装依赖:`pip install -r requirements.txt`
1010
2. 配置脚本中相关参数:
1111
```
@@ -33,13 +33,13 @@
3333

3434
## 开发日志
3535
#### 2016-9-29
36-
- Github今日热点项目不统计自己的项目
36+
- GitHub今日热点项目不统计自己的项目
3737
- 错误日志放到脚本的同目录下
3838

3939
#### 2016-9-24
4040
实现根据star数量,从高到低展示。
4141
#### 2016-9-5
42-
实现请求Github api获取关注的用户star的项目、过滤内容、定时发邮件
42+
实现请求GitHub api获取关注的用户star的项目、过滤内容、定时发邮件
4343

4444
Todo:
4545

File renamed without changes.
File renamed without changes.

script/make_content/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# GitHub MakeContent
2+
>兴趣是最好的老师,[《HelloGitHub》](https://github.com/521xueweihan/HelloGitHub)就是帮你找到兴趣!
3+
4+
![](https://github.com/521xueweihan/HelloGitHub/blob/master/01/img/hello-github.jpg)
5+
6+
7+
## 运行步骤
8+
后面的月刊都通过这个脚本生成,这样如果通用内容部分需要修改,就只需要使用脚本重新生成月刊,而不需要手动修改已发布的所有期的内容。后面还会持续开发~
9+
10+
```
11+
python make_content.py temple_path content_path 期数
12+
13+
输出结果为:生成的文件所在目录
14+
```

script/make_content/make_content.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
#
4+
# Author : XueWeiHan
5+
6+
# Date : 16/10/21 下午1:41
7+
# Desc : HelloGitHub项目——生成月刊脚本
8+
"""
9+
该脚本主要用于:生成月刊
10+
11+
《HelloGitHub》月刊每期内容都遵循统一格式,如果需要对通用部分的内容进行修改,需要手动修改每一
12+
期的内容,这是不优雅的。
13+
14+
所以,我打算写个脚本,用于生成月刊,这样如果修改了通用内容部分,就只需要重新生成月刊,而不需要
15+
手动修改已发布的所有期的内容。
16+
"""
17+
import sys
18+
import os
19+
20+
CONTENT_FLAG = '{{ hello_github_content }}'
21+
NUM_FLAG = '{{ hello_github_num }}'
22+
23+
24+
class InputError(Exception):
25+
def __init__(self, message):
26+
self.message = message
27+
28+
def __str__(self):
29+
return repr(self.message)
30+
31+
32+
def check_path(input_path):
33+
"""
34+
检查输入的路径是否存在
35+
"""
36+
for fi_input in input_path[:-1]:
37+
if not os.path.exists(fi_input):
38+
error_message = 'Path: ' + fi_input + ', not exists.'
39+
raise InputError(error_message)
40+
41+
42+
def get_args():
43+
"""
44+
检查输入的参数是否合法
45+
"""
46+
input_list = sys.argv
47+
48+
if len(input_list) < 2:
49+
raise InputError('Input error: need args')
50+
elif len(input_list) != 4:
51+
raise InputError('Input error: just need 3 args')
52+
else:
53+
check_path(input_list)
54+
return input_list[1:]
55+
56+
57+
def read_file(input_path):
58+
with open(input_path, 'r') as fb:
59+
return fb.read()
60+
61+
62+
def write_file(output_path, output_data):
63+
with open(output_path, 'w') as fb:
64+
fb.write(output_data)
65+
66+
67+
def make_content(input_args):
68+
temple_path = input_args[0]
69+
content_path = input_args[1]
70+
num = input_args[2]
71+
if len(num) == 1:
72+
num = '0' + num
73+
74+
temple_data = read_file(temple_path).replace(NUM_FLAG, num)
75+
content_path = read_file(content_path)
76+
77+
output_data = temple_data.replace(CONTENT_FLAG, content_path)
78+
79+
write_file(os.path.join(os.path.abspath(os.curdir), 'HelloGitHub{num}.md'.format(num=num)), output_data)
80+
81+
if __name__ == '__main__':
82+
args = get_args()
83+
make_content(args)
84+
print os.path.abspath(os.curdir)

script/make_content/temple.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#《HelloGitHub》第{{ hello_github_num }}期
2+
>兴趣是最好的老师,[《HelloGitHub》](https://github.com/521xueweihan/HelloGitHub)就是帮你找到兴趣!
3+
4+
![](https://github.com/521xueweihan/HelloGitHub/blob/master/01/img/hello-github.jpg)
5+
6+
## 简介
7+
最开始我只是想把自己在浏览GitHub过程中,发现的有意思、高质量、容易上手的项目收集起来,这样便于以后查找和学习。后来一想,如果给这些GitHub项目都加上简单的效果图和一些通俗易懂的中文介绍。应该能够帮助到我这样的新手激发兴趣去参与、学习这些优秀、好玩的开源项目。
8+
9+
所以,我就做了一个面向**编程新手****热爱编程****对开源社区感兴趣** 的人群的月刊,月刊的内容包括:**各种编程语言的项目****各种让生活变得更美好的工具****书籍、学习笔记、教程等**。这些项目都是非常容易上手,而且非常Cool,主要是希望大家能动手用起来,加入到**开源社区**中。会编程的可以贡献代码,不会编程的可以反馈使用这些工具中的bug、帮着宣传你觉得优秀的项目、不要吝啬你的⭐️。你将学习到更多编程知识、提高自己的编程技巧、发现自己的**兴趣**
10+
11+
最后[《HelloGitHub》](https://github.com/521xueweihan/HelloGitHub)这个项目就诞生了!😁
12+
13+
{{ hello_github_content }}
14+
15+
## 声明
16+
如果你发现了好玩、有意义的开源项目,[点击这里](https://github.com/521xueweihan/HelloGitHub/issues/new)分享你觉得有意思的项目。
17+
18+
- 分享项目格式:项目名称——项目地址:项目描述(中文),追求完美👉项目上手demo、有图有真相~
19+
20+
或许你分享的项目会让别人由衷的感慨:“原来还有这么有意思的项目!编程可以这么酷!”
21+
22+
欢迎转载,请注明出处和作者,同时保留声明和联系方式。
23+
24+
## 联系方式
25+
- GitHub:[削微寒](https://github.com/521xueweihan)
26+
27+
- 博客园:[削微寒](http://www.cnblogs.com/xueweihan/)
28+
29+

0 commit comments

Comments
 (0)