Skip to content

Commit

Permalink
Merge pull request #48 from LuuMing/dev
Browse files Browse the repository at this point in the history
命令行参数读取的支持
  • Loading branch information
bestony committed Oct 13, 2018
2 parents 10c3248 + 0518c21 commit 533e472
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
20 changes: 15 additions & 5 deletions grank/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import os
import sys
import warnings

warnings.filterwarnings('ignore')

config = None # 配置实例
if sys.version_info[0] != 3:
"""设置 Python 3 的判断如果不是 Python 3 则退出"""
print("This script requires Python 3")
Expand All @@ -14,10 +13,19 @@
from .libs import query
from .script import activity, crawler, social


@click.group()
def main():
@click.option('--token',help='Your github token')
@click.option('--start',help='Start time: yyyy-mm-dd')
@click.option('--stop',help='Stop time: yyyy-mm-dd')
@click.option('--askrule',help='Ask rule: 1-Yes 0-No')
@click.option('--rule',help='rule: corp|inc')
def main(token,start,stop,askrule,rule):
"""Grank Command"""
global config
if (token or start or stop or askrule or rule):
config = helpers.get_config_instance(token=token,start=start,stop=stop,askrule=askrule, rule=rule)
else:
config = None
pass


Expand Down Expand Up @@ -52,7 +60,9 @@ def checklogin():
@click.argument('args', nargs=-1)
def analy(args):
"""Analyse a Github User or Organization"""
config = helpers.get_config()
global config
if config is None:
config = helpers.get_config()
if len(args) == 0:
click.echo('grank analy owner [repo]')
return False
Expand Down
27 changes: 16 additions & 11 deletions grank/libs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,28 @@ def get_config():
"""读取配置文件并返回对应实例"""
configInstance = configparser.ConfigParser()
if not check_exist():
configInstance = configparser.ConfigParser()
configInstance["login"] = {}
configInstance["login"]["token"] = ''
configInstance["social"] = {}
configInstance["social"]["rule"] = 'corp|inc'
configInstance["time"] = {}
configInstance["time"]["start_time"] = '2017-01-01'
configInstance["time"]["end_time"] = datetime.date.today().strftime(
'%Y-%m-%d') # 使用今天的日期
configInstance["rank"] = {}
configInstance["rank"]["top"] = '3' # 默认制作前三名的综合图像
configInstance = get_config_instance()
with open('grank.ini', 'w') as configfile:
configInstance.write(configfile)
configInstance.read('grank.ini')
return configInstance
pass

def get_config_instance(token=None, rule=None, start=None, stop=None, top=None, askrule=None):
configInstance = configparser.ConfigParser()
configInstance["login"] = {}
configInstance["login"]["token"] = token if token is not None else ''
configInstance["social"] = {}
configInstance["social"]["askrule"] = askrule if askrule is not None else '1'
configInstance["social"]["rule"] = rule if rule is not None else 'corp|inc'
configInstance["time"] = {}
configInstance["time"]["start_time"] = start if start is not None else '2017-01-01'
configInstance["time"]["end_time"] = stop if stop is not None else datetime.date.today().strftime(
'%Y-%m-%d') # 使用今天的日期
configInstance["rank"] = {}
configInstance["rank"]["top"] = top if top is not None else '3'# 默认制作前三名的综合图像
return configInstance
pass

def set_user_token(token):
"""向配置文件写入用户 Token"""
Expand Down

0 comments on commit 533e472

Please sign in to comment.