Skip to content

Commit

Permalink
修复一卡车的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
unstartdev committed Nov 25, 2018
1 parent 67d561a commit 382e2d3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
26 changes: 15 additions & 11 deletions get.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# -*- coding: UTF-8 -*-
import urllib.request
import json
import urllib.request

import restartmodule


def getpicinfo(cate,act):
"用于获取图片信息"
cate = urllib.parse.quote(cate)
Expand All @@ -11,10 +14,7 @@ def getpicinfo(cate,act):
if decodedata['status'] == 'ok':
picdata = decodedata['pictures'][0]
print('PID: '+ picdata['PID'] + '\n' + picdata['p_title'] + '\n' + picdata['p_content'] + '提交者:' + picdata['username'] + '\n' + '链接:' + picdata['p_link'] + '\n' + '分类:' + picdata['TNAME'])
global piclink
piclink = picdata['p_link']
global picid
picid = picdata['PID']
return picdata
else:
print("连图也没有")
restartmodule.restart_program()
Expand All @@ -23,11 +23,15 @@ def getpicfile(link, picid):
"用于获取图片文件"
import os
import filetype
if not os.path.exists(os.environ['HOME'] + "TUJIANPIC"):
os.mkdir(os.environ['HOME'] + '/TUJIANPIC', 755)
path = os.environ['HOME'] + "/TUJIANPIC/" + picid
print(link)
storagedir = os.path.expanduser('~') + '/TUJIANPIC'
if not os.path.exists(storagedir):
os.mkdir(storagedir, 755)
path = storagedir + picid
urllib.request.urlretrieve(link, path)
pictype = filetype.guess(path)
os.rename(path, path + pictype.extension)
global pathfnish
pathfnish = path + pictype.extension
if not os.path.exists(path + '.' + pictype.extension):
os.rename(path, path + '.' + pictype.extension)
else:
os.remove(path)
return path + '.' + pictype.extension
4 changes: 3 additions & 1 deletion restartmodule.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# -*- coding: UTF-8 -*-
import os
import sys


def restart_program():
python = sys.executable
os.execl(python, python, * sys.argv)

def stop_program():
sys.exit(0)
sys.exit(0)
16 changes: 8 additions & 8 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: UTF-8 -*-
import get

#user_agent = "tujianx-python/0x38"
piclink = ""
picid = ""
pathfnish = ""
catelist = ['杂烩', '二次元', '电脑壁纸']
catestr = "0.杂烩\n1.二次元\n2.电脑壁纸"
actlist = ['today']
Expand All @@ -12,18 +10,20 @@
if selectactup == 0:
print(catestr)
selectcateup = int(input('Enter you want to see:'))
get.getpicinfo(catelist[selectcateup], actlist[selectactup])
picdata = get.getpicinfo(catelist[selectcateup], actlist[selectactup])
selopen = input('要打开它吗?(Y/N)')
if selopen == 'Y':
get.getpicfile(piclink, picid)
print('Opening...')
pathlast = get.getpicfile(picdata['p_link'], picdata['PID'])
from PIL import Image
img = Image.open(pathfnish)
print(pathlast)
img = Image.open(pathlast)
img.show()
elif selopen == "N":
selsave = input('单独保存它?(Y/N)')
if selsave == "Y":
get.getpicfile(piclink, picid)
print(pathfnish)
pathlast = get.getpicfile(picdata['p_link'], picdata['PID'])
print(pathlast)
elif selsave == "N":
import restartmodule
selquit = input('退出或返回主菜单(Q/R)')
Expand Down

0 comments on commit 382e2d3

Please sign in to comment.