diff --git a/code/shorturl/app.py b/code/shorturl/app.py index 184e58d..8754e63 100644 --- a/code/shorturl/app.py +++ b/code/shorturl/app.py @@ -1,58 +1,58 @@ -from flask import Flask, render_template, request, redirect -import pymysql -from bases import Bases - - -bases = Bases() -host = 'http://127.0.0.1:5000/' - - -try: - connection = pymysql.connect(host='localhost', - port=3306, - user='root', - password='root', - db='test', - charset='utf8' - ) -except pymysql.Error: - raise - -cursor = connection.cursor() - - -app = Flask('__name__') - -@app.route('/') -def index(): - return render_template('index.html') - - -@app.route('/gen_short_url', methods=['POST']) -def gen_short_url(): - long_url = request.form.get('long_url') - # 将长链接存入数据库 - try: - cursor.execute('insert into urls (url) values ("{}")'.format(long_url)) - connection.commit() - except pymysql.Error: - raise - # 获取id - last_id = cursor.lastrowid - # 将 id 转化为 62 进制 - encode = bases.toBase62(last_id) - short_url = host + encode - return render_template('index.html', short_url=short_url) - - -@app.route('/') -def redirect_url(encode_id): - id = bases.fromBase62(encode_id) - try: - cursor.execute('select url from urls where id = {}'.format(id)) - connection.commit() - url = cursor.fetchone() - return redirect(url[0]) - except pymysql.Error: - raise - +from flask import Flask, render_template, request, redirect +import pymysql +from bases import base62 + + +bases = Bases() +host = 'http://127.0.0.1:5000/' + + +try: + connection = pymysql.connect(host='localhost', + port=3306, + user='root', + password='root', + db='test', + charset='utf8' + ) +except pymysql.Error: + raise + +cursor = connection.cursor() + + +app = Flask('__name__') + +@app.route('/') +def index(): + return render_template('index.html') + + +@app.route('/gen_short_url', methods=['POST']) +def gen_short_url(): + long_url = request.form.get('long_url') + # 将长链接存入数据库 + try: + cursor.execute('insert into urls (url) values ("{}")'.format(long_url)) + connection.commit() + except pymysql.Error: + raise + # 获取id + last_id = cursor.lastrowid + # 将 id 转化为 62 进制 + encode = bases.toBase62(last_id) + short_url = host + encode + return render_template('index.html', short_url=short_url) + + +@app.route('/') +def redirect_url(encode_id): + id = bases.fromBase62(encode_id) + try: + cursor.execute('select url from urls where id = {}'.format(id)) + connection.commit() + url = cursor.fetchone() + return redirect(url[0]) + except pymysql.Error: + raise + diff --git a/python_meme_game b/python_meme_game new file mode 160000 index 0000000..1407d0c --- /dev/null +++ b/python_meme_game @@ -0,0 +1 @@ +Subproject commit 1407d0cea8206042cab3c5279464eae7dcd578c4 diff --git a/vip/kelvinweng/Kelvin_meme_game/__pycache__/config.cpython-39.pyc b/vip/kelvinweng/Kelvin_meme_game/__pycache__/config.cpython-39.pyc new file mode 100644 index 0000000..bbd6222 Binary files /dev/null and b/vip/kelvinweng/Kelvin_meme_game/__pycache__/config.cpython-39.pyc differ diff --git a/vip/kelvinweng/Kelvin_meme_game/__pycache__/meme.cpython-39.pyc b/vip/kelvinweng/Kelvin_meme_game/__pycache__/meme.cpython-39.pyc new file mode 100644 index 0000000..65365c9 Binary files /dev/null and b/vip/kelvinweng/Kelvin_meme_game/__pycache__/meme.cpython-39.pyc differ diff --git a/vip/kelvinweng/Kelvin_meme_game/config.py b/vip/kelvinweng/Kelvin_meme_game/config.py new file mode 100644 index 0000000..edb36f3 --- /dev/null +++ b/vip/kelvinweng/Kelvin_meme_game/config.py @@ -0,0 +1,12 @@ +class Config: + def __init__(self): + self.game_title = "吃shi啦你" + self.screen_width = 900 + self.screen_height = 600 + self.screen_bg_color = (255,255,255) + + # meme + self.meme_head_size = (60,60) + self.meme_head_image = 'images/head.png' + self.meme_body_block_size = 30 + self.meme_body_color = (0,0,0) diff --git a/vip/kelvinweng/Kelvin_meme_game/food.py b/vip/kelvinweng/Kelvin_meme_game/food.py new file mode 100644 index 0000000..fb10af3 --- /dev/null +++ b/vip/kelvinweng/Kelvin_meme_game/food.py @@ -0,0 +1,22 @@ +import pygame +import random + +class Food: + def __init__(self,meme_game): + self.config = meme_game.config + self.screen = meme_game.screen + self.game = meme_game + + self.food = pygame.image.load(self.config.food_image) + self.food = pygame.transform.scale(self.food,self.config.food_size) + self.food_rect = self.food.get_rect() + self.food_rect.x = 585 + self.food_rect.y = 30 + + del blit_food(self): + screen_rect = self.screen.get_rect() + x_num = screen_rect.width + y_num = screen_rect.height + self.food_rect.x = random.randint(0,x_num-1)*30 + self.food_rect.y = random.randint(0,y_num-1)*30 + self.game.play_sound('chishi') diff --git a/vip/kelvinweng/Kelvin_meme_game/images/food.png b/vip/kelvinweng/Kelvin_meme_game/images/food.png new file mode 100644 index 0000000..59de5a7 Binary files /dev/null and b/vip/kelvinweng/Kelvin_meme_game/images/food.png differ diff --git a/vip/kelvinweng/Kelvin_meme_game/images/head.png b/vip/kelvinweng/Kelvin_meme_game/images/head.png new file mode 100644 index 0000000..c1fd3a4 Binary files /dev/null and b/vip/kelvinweng/Kelvin_meme_game/images/head.png differ diff --git a/vip/kelvinweng/Kelvin_meme_game/meme.py b/vip/kelvinweng/Kelvin_meme_game/meme.py new file mode 100644 index 0000000..7eef693 --- /dev/null +++ b/vip/kelvinweng/Kelvin_meme_game/meme.py @@ -0,0 +1,41 @@ +import pygame + +class Meme(): + def __init__(self,meme_game): + self.screen = meme_game.screen + self.config = meme_game.config + + self.head = pygame.image.load(self.config.meme_head_image) + self.head = pygame.transform.scale(self.head,self.config.meme_head_size) + self.head_rect = self.head.get_rect() + self.head_rect.center = self.screen.get_rect().center + + self.body_rect = pygame.Rect( + 0, + 0, + self.config.meme_body_block_size, + self.config.meme_body_block_size + ) + + self.len = 3 + self.body = [(0,0),(130,200),(160,200)] + + self.head_rect.x = 160 + self.head_rect.y = 0 + + self.direction = 'k' #jkhl ----> 下上左右 + + def blit_meme(self): + for item in self.body: + self.body_rect.x = item[0] + self.body_rect.y = item[1] + pygame.draw.rect(self.screen,self.config.meme_body_color,self.body_rect) + self.screen.blit(self.head,self.head_rect) + + def move(self): + head = self.body[0] + if self.direction == 'k': + now_head = (head[0],head[1]+30) + self.body.insert(0,now_head) + self.head_rect.x = now_head[0] - 15 + self.head_rect.y = now_head[1] + 15 diff --git a/vip/kelvinweng/Kelvin_meme_game/meme_game.py b/vip/kelvinweng/Kelvin_meme_game/meme_game.py new file mode 100644 index 0000000..706a175 --- /dev/null +++ b/vip/kelvinweng/Kelvin_meme_game/meme_game.py @@ -0,0 +1,35 @@ +import sys +import pygame +from config import Config +from meme import Meme + +class MemeGame: + def __init__(self): + pygame.init() + self.config = Config() + + pygame.display.set_caption(self.config.game_title) + + self.screen = pygame.display.set_mode((self.config.screen_width,self.config.screen_height)) + + self.meme = Meme(self) + + def _listen_event(self): + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit() + + def _update_screen(self): + self.screen.fill(self.config.screen_bg_color) + + + def run_game(self): + while True: + self._listen_event() + self._update_screen() + self.meme.blit_meme() + pygame.display.flip() + +if __name__ == '__main__': + meme_game = MemeGame() + meme_game.run_game() diff --git a/vip/kelvinweng/Kelvin_meme_game/sound/chishi.mp3 b/vip/kelvinweng/Kelvin_meme_game/sound/chishi.mp3 new file mode 100644 index 0000000..1e2ac3c Binary files /dev/null and b/vip/kelvinweng/Kelvin_meme_game/sound/chishi.mp3 differ diff --git a/vip/kelvinweng/Kelvin_meme_game/sound/zhenxiang.mp3 b/vip/kelvinweng/Kelvin_meme_game/sound/zhenxiang.mp3 new file mode 100644 index 0000000..73a1937 Binary files /dev/null and b/vip/kelvinweng/Kelvin_meme_game/sound/zhenxiang.mp3 differ diff --git a/vip/kelvinweng/Niubility/auido.mp3 b/vip/kelvinweng/Niubility/auido.mp3 new file mode 100644 index 0000000..a82f262 Binary files /dev/null and b/vip/kelvinweng/Niubility/auido.mp3 differ diff --git a/vip/kelvinweng/Niubility/bg.png b/vip/kelvinweng/Niubility/bg.png new file mode 100644 index 0000000..ade75f1 Binary files /dev/null and b/vip/kelvinweng/Niubility/bg.png differ diff --git a/vip/kelvinweng/Niubility/cucumber.png b/vip/kelvinweng/Niubility/cucumber.png new file mode 100644 index 0000000..6b100c4 Binary files /dev/null and b/vip/kelvinweng/Niubility/cucumber.png differ diff --git a/vip/kelvinweng/Niubility/error.txt b/vip/kelvinweng/Niubility/error.txt new file mode 100644 index 0000000..7e3d098 --- /dev/null +++ b/vip/kelvinweng/Niubility/error.txt @@ -0,0 +1 @@ +{"err_detail":"16: Open api characters limit reached","err_msg":"16: Open api characters limit reached","err_no":502,"err_subcode":16,"tts_logid":3204479260} diff --git a/vip/kelvinweng/Niubility/floor.png b/vip/kelvinweng/Niubility/floor.png new file mode 100644 index 0000000..993cd48 Binary files /dev/null and b/vip/kelvinweng/Niubility/floor.png differ diff --git a/vip/kelvinweng/Niubility/game.py b/vip/kelvinweng/Niubility/game.py new file mode 100644 index 0000000..578964b --- /dev/null +++ b/vip/kelvinweng/Niubility/game.py @@ -0,0 +1,133 @@ +import pygame +from pygame.locals import * +import random + + + +caption_width = 300 +caption_height = 600 +game_title = '牛逼的黄瓜' + +hero_width = 50 +hero_height = 50 + +cucumber_width = 80 +cucumber_height = 380 + +floor_width = caption_width +floor_height = 100 + +speed = 10 +space = 140 + +score = 0 + +class Hero(pygame.sprite.Sprite): + + + def __init__(self,top=0): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load('hero.png').convert_alpha() + self.image = pygame.transform.scale(self.image,(hero_width,hero_height)) + self.rect = self.image.get_rect() + self.rect.left = caption_width/2 - hero_width + self.rect.top = caption_height/2 - hero_height - top + self.speed = speed + + def update(self): + self.speed += 1 + self.rect.top += self.speed + + def fly(self): + self.speed = -speed + + +class Cucumber(pygame.sprite.Sprite): + + def __init__(self,change,left,top): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load('cucumber.png').convert_alpha() + self.image = pygame.transform.scale(self.image,(cucumber_width,cucumber_height)) + self.rect = self.image.get_rect() + self.rect.left = left + if change: + self.image = pygame.transform.flip(self.image,False,True) + self.rect.top = - (self.rect.bottom - top) + else: + self.rect.top = caption_height - top + + def update(self): + self.rect.left -= speed + + + +class Floor(pygame.sprite.Sprite): + + def __init__(self,left): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load('floor.png').convert_alpha() + self.image = pygame.transform.scale(self.image,(floor_width,floor_height)) + self.rect = self.image.get_rect() + self.rect.left = left + self.rect.top = caption_height - floor_height + +def generate_Cucumber(left): + top = random.randint(100,300) + cucumber = Cucumber(False,left,top) + cucumber_changed = Cucumber(True,left,caption_height - top - space) + return cucumber,cucumber_changed + +if __name__ == '__main__': + pygame.init() + game_font = pygame.font.SysFont('arial',16) + caption = pygame.display.set_mode((caption_width,caption_height)) + pygame.display.set_caption(game_title) + + background = pygame.image.load('bg.png') + background = pygame.transform.scale(background,(caption_width,caption_height)) + + hero_group = pygame.sprite.Group() + hero = Hero() + hero_group.add(hero) + + floor_group = pygame.sprite.Group() + floor = Floor(0) + floor_group.add(floor) + + + cucumber_group = pygame.sprite.Group() + cucumbers1 = generate_Cucumber(300) + cucumber_group.add(cucumbers1[0]) + cucumber_group.add(cucumbers1[1]) + + clock = pygame.time.Clock() + + while True: + clock.tick(25) + caption.blit(background,(0,0)) + caption.blit(game_font.render('score:%d'%score,True,[0,0,0]),[20,20]) + + for event in pygame.event.get(): + if event.type == KEYDOWN: + if event.key == K_SPACE: + hero.fly() + + if cucumber_group.sprites()[0].rect.left < -(caption_width): + cucumber_group.remove(cucumber_group.sprites()) + cucumbers = generate_Cucumber(caption_width) + cucumber_group.add(cucumbers[0]) + cucumber_group.add(cucumbers[1]) + score += 1 + + hero_group.update() + hero_group.draw(caption) + cucumber_group.update() + cucumber_group.draw(caption) + floor_group.draw(caption) + pygame.display.update() + + #if pygame.sprite.groupcollide(hero_group,floor_group,False,False)\ + # or pygame.sprite.groupcollide(hero_group,cucumber_group,False,False): + # pygame.quit() + # quit() + diff --git a/vip/kelvinweng/Niubility/gameOrigin.py b/vip/kelvinweng/Niubility/gameOrigin.py new file mode 100644 index 0000000..be17594 --- /dev/null +++ b/vip/kelvinweng/Niubility/gameOrigin.py @@ -0,0 +1,149 @@ +import pygame +from pygame.locals import * +import random + +caption_width = 300 +caption_height = 600 +game_title = '牛逼的黄瓜' + +cucumber_width = 80 +cucumber_height = 380 + +speed = 10 +space = 140 + +floor_width = caption_width +floor_height = 100 + +hero_width = 50 +hero_height = 50 + +score = 0 + +class Hero(pygame.sprite.Sprite): + + def __init__(self, top=0): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load('hero.png').convert_alpha() + self.image = pygame.transform.scale(self.image, (hero_width, hero_height)) + self.rect = self.image.get_rect() + self.rect.left = caption_width / 2 - hero_width + self.rect.top = caption_height / 2 - hero_height - top + self.speed = speed + + def update(self): + self.speed += 1 + self.rect.top += self.speed + + def fly(self): + self.speed = -speed + + +class Cucumber(pygame.sprite.Sprite): + + def __init__(self, change, left, top): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load('cucumber.png').convert_alpha() + self.image = pygame.transform.scale(self.image, (cucumber_width, cucumber_height)) + + self.rect = self.image.get_rect() + self.rect.left = left + + if change: + self.image = pygame.transform.flip(self.image, False, True) + self.rect.top = - (self.rect.bottom - top) + else: + self.rect.top = caption_height - top + + + def update(self): + self.rect.left -= speed + + +class Floor(pygame.sprite.Sprite): + + def __init__(self, left): + pygame.sprite.Sprite.__init__(self) + self.image = pygame.image.load('floor.png').convert_alpha() + self.image = pygame.transform.scale(self.image, (floor_width, floor_height)) + + self.rect = self.image.get_rect() + self.rect.left = left + self.rect.top = caption_height - floor_height + + + + +def generate_Cucumber(left): + top = random.randint(100, 300) + cucumber = Cucumber(False, left, top) + cucumber_changed = Cucumber(True, left, caption_height - top - space) + return cucumber, cucumber_changed + +def go_die(): + + caption.blit(pygame.image.load('a.jpg'),(0, 0)) + pygame.display.update() + +if __name__ == '__main__': + pygame.init() + game_font = pygame.font.SysFont('arial', 16, True) + caption = pygame.display.set_mode((caption_width, caption_height)) + pygame.display.set_caption(game_title) + + background = pygame.image.load('bg.png') + background = pygame.transform.scale(background, (caption_width, caption_height)) + + hero_group = pygame.sprite.Group() + hero = Hero() + hero_group.add(hero) + + + floor_group = pygame.sprite.Group() + floor = Floor(0) + floor_group.add(floor) + + + cucumber_group = pygame.sprite.Group() + cucumbers1 = generate_Cucumber(300) + cucumber_group.add(cucumbers1[0]) + cucumber_group.add(cucumbers1[1]) + + clock = pygame.time.Clock() + + + while True: + + clock.tick(25) + caption.blit(background, (0, 0)) + caption.blit(game_font.render('score:%d' % score, True, [255, 255, 255]), [20, 20]) + + for event in pygame.event.get(): + if event.type == KEYDOWN: + if event.key == K_SPACE: + hero.fly() + + if cucumber_group.sprites()[0].rect.left < -(caption_width): + cucumber_group.remove(cucumber_group.sprites()) + cucumbers = generate_Cucumber(caption_width) + cucumber_group.add(cucumbers[0]) + cucumber_group.add(cucumbers[1]) + score += 1 + + + hero_group.update() + hero_group.draw(caption) + cucumber_group.update() + cucumber_group.draw(caption) + floor_group.draw(caption) + pygame.display.update() + + + if pygame.sprite.groupcollide(hero_group, floor_group, False, False)\ + or pygame.sprite.groupcollide(hero_group, cucumber_group, False, False): + # go die + pygame.quit() + quit() + + + # 关注公众号:学习python的正确姿势,收获更多精彩 diff --git a/vip/kelvinweng/Niubility/hero.png b/vip/kelvinweng/Niubility/hero.png new file mode 100644 index 0000000..6cbdb2c Binary files /dev/null and b/vip/kelvinweng/Niubility/hero.png differ diff --git a/vip/kelvinweng/Niubility/testVoice.py b/vip/kelvinweng/Niubility/testVoice.py new file mode 100644 index 0000000..827a68b --- /dev/null +++ b/vip/kelvinweng/Niubility/testVoice.py @@ -0,0 +1,17 @@ +from aip import AipSpeech + +APP_ID = '30817419' +API_KEY= '1VCfu6wxK4v2eMbREm02DsXe' +SECRET_KEY = 'ozoGHmabKzIyPFaO99V8h4kDWicNMC0U' + +client = AipSpeech(APP_ID,API_KEY,SECRET_KEY) + +result = client.synthesis(' 你真帅啊','zh',1,{ + 'spd':3, + 'vol':5, + 'per':111, + }) +print (result) +if not isinstance(result,dict): + with open('auido.mp3','wb') as f: + f.write(result) diff --git a/vip/kelvinweng/Spider/biaoqingbao.py b/vip/kelvinweng/Spider/biaoqingbao.py new file mode 100644 index 0000000..09739c5 --- /dev/null +++ b/vip/kelvinweng/Spider/biaoqingbao.py @@ -0,0 +1,77 @@ +#-*- coding:UTF-8 -*- +import os +from time import time + +import requests +from bs4 import BeautifulSoup +from queue import Queue +from threading import Thread + + +class DownloadBiaoqingbao(Thread): + + def __init__(self, queue, path): + Thread.__init__(self) + self.queue = queue + self.path = 'C:\\Users\\10500957\\Pictures\\' + if not os.path.exists(path): + os.makedirs(path) + + def run(self): + while True: + url = self.queue.get() + try: + # print(url) + download_biaoqingbaos(url, self.path) + finally: + self.queue.task_done() + + +def download_biaoqingbaos(url, path): + + response = requests.get(url) + soup = BeautifulSoup(response.text, 'html.parser') + img_list = soup.find_all('img') + + for img in img_list: + image = img.get('src') + print (image) + title = img.get('alt') + print('下载图片: ', title) + + try: + with open(path + title + os.path.splitext(image)[-1], 'wb') as f: + img = requests.get(image).content + f.write(img) + except OSError: + print('length failed') + break + + +if __name__ == '__main__': + + start = time() + + # 构建所有的链接 + url = 'https://www.doutuwang.com/category/dashijian/page/2' + #urls = [_url.format(page=page) for page in range(1, 2+1)] + + queue = Queue() + path = 'C:\\Users\\10500957\\Pictures\\' + + # 创建线程 + for x in range(10): + worker = DownloadBiaoqingbao(queue, path) + worker.daemon = True + worker.start() + + # 加入队列 + #for url in urls: + queue.put(url) + + queue.join() + + print('下载完毕耗时: ', time()-start) + + + diff --git a/vip/kelvinweng/Spider/search.py b/vip/kelvinweng/Spider/search.py new file mode 100644 index 0000000..b750f36 --- /dev/null +++ b/vip/kelvinweng/Spider/search.py @@ -0,0 +1,29 @@ +#-*- coding:UTF-8 -*- + +import glob,os +import itchat +import time +from itchat.content import TEXT,PICTURE + + +itchat.auto_login(hotReload=True) +itchat.run() +current_path = os.getcwd() + +imgs = [] + +def searchImage(text): + print('收到关键词: ',text) + for name in glob.glob('C:\\Users\\10500957\\github\\fxxkpython\\vip\\kelvinweng\\Spider\\*'+ text +'*.*'): + imgs.append(name) + +@itchat.msg_register(['PICTURE','TEXT']) +def text_reply(msg): + searchImage(msg.text) + for img in imgs[:2]: + msg.user.send_image(img) + time.sleep(0.4) + print('开始发送表情:',img) + imgs.clear() + + diff --git a/vip/kelvinweng/Spider/test.py b/vip/kelvinweng/Spider/test.py new file mode 100644 index 0000000..fb85647 --- /dev/null +++ b/vip/kelvinweng/Spider/test.py @@ -0,0 +1,73 @@ +#-*- coding:utf-8 -*- +import requests +import os +import bs4 +import time +import re +from bs4 import BeautifulSoup + +download_url = 'https://www.doutuwang.com/category/dashijian/page/2' + +page_num = 25 + +file_name = "D:\\测试图库" + +image_down_url_1 = 'https://www.doutuwang.com' + +def CreateFolder(file): + flag = 1 + while flag == 1: + if not os.path.exists(file): + os.mkdir(file) + flag = 0 + else: + print('该文件已存在,请重新输入') + flag = 1 + time.sleep(1) + + path = os.path.abspath(file) + #print (path) + +def DownloadPicture(download_url,list,path): + r = requests.get(url=download_url,timeout=20) + r.encoding = r.apparent_encoding + soup = BeautifulSoup(r.text,'html.parser') + + + tag = soup.find_all('img') + + j = 0 + for i in range(list,list+3): + if(j ') +def redirect_url(encode_url): + id = base62.decode(encode_url) + conn = sqlite3.connect('url.db') + cursor = conn.cursor() + try: + cursor.execute("SELECT longurl FROM url WHERE id LIKE ?",str(id)) + conn.commit() + url = cursor.fetchone() + return redirect(location=url[0]) + except sqlite3.Error as e: + print (str(e)) + + + +if __name__ == '__main__': + app.run() diff --git a/vip/kelvinweng/shorturl/creatdb.py b/vip/kelvinweng/shorturl/creatdb.py new file mode 100644 index 0000000..bd54218 --- /dev/null +++ b/vip/kelvinweng/shorturl/creatdb.py @@ -0,0 +1,5 @@ +import sqlite3 + +conn = sqlite3.connect('url.db') +conn.execute("CREATE TABLE url (id INTEGER PRIMARY KEY,longurl char(1000) NOT NULL)") +conn.commit() diff --git a/vip/kelvinweng/shorturl/longtoshort.py b/vip/kelvinweng/shorturl/longtoshort.py new file mode 100644 index 0000000..54ef2c6 --- /dev/null +++ b/vip/kelvinweng/shorturl/longtoshort.py @@ -0,0 +1,6 @@ +import pyshorteners as psn + + +url = "http://www.baidu.com" +u = psn.Shortener().clckru.short(url) +print (u) diff --git a/vip/kelvinweng/shorturl/templates/index.html b/vip/kelvinweng/shorturl/templates/index.html new file mode 100644 index 0000000..74b0d19 --- /dev/null +++ b/vip/kelvinweng/shorturl/templates/index.html @@ -0,0 +1,31 @@ + + + + 短连接生成器 + + + + + +
+

短链接生成器

+

短就完事了

+
+ +
+
+
+ + +
+ +
+ + {%if short_url%} +
+ + {{short_url}} +
+ {%endif%} + + \ No newline at end of file diff --git a/vip/kelvinweng/shorturl/url.db b/vip/kelvinweng/shorturl/url.db new file mode 100644 index 0000000..42cc6a6 Binary files /dev/null and b/vip/kelvinweng/shorturl/url.db differ diff --git "a/vip/kelvinweng/shorturl/\345\274\200\345\217\221\347\254\224\350\256\260.txt" "b/vip/kelvinweng/shorturl/\345\274\200\345\217\221\347\254\224\350\256\260.txt" new file mode 100644 index 0000000..392dd40 --- /dev/null +++ "b/vip/kelvinweng/shorturl/\345\274\200\345\217\221\347\254\224\350\256\260.txt" @@ -0,0 +1,10 @@ +1.原实现方法的bases库已经无法使用base62模块了,改用base62库 +2.用sqlite3替换mysql的实现方法,也很方便 +3.寻找方法时,还发现了pyshorteners库,其中pyshorteners.Shortener().clckru.short(),可以直接转化长链接,网上还分享了几个不同的短链域名: + +dagd.py +osdb.py +qpsru.py + +具体用法可以参考:longtoshort.py +来源:https://www.jb51.net/article/268750.htm \ No newline at end of file diff --git a/vip/kelvinweng/todo/createdb.py b/vip/kelvinweng/todo/createdb.py new file mode 100644 index 0000000..6d538ef --- /dev/null +++ b/vip/kelvinweng/todo/createdb.py @@ -0,0 +1,8 @@ +import sqlite3 + +conn = sqlite3.connect('todo.db') +conn.execute("CREATE TABLE todo (id INTEGER PRIMARY KEY, task char(100) NOT NULL,status bool NOT NUll)") +conn.execute("INSERT INTO todo (task,status) VALUES ('加十个小姐姐的微信',0)") +conn.execute("INSERT INTO todo (task,status) VALUES ('赚10个亿',1)") +conn.execute("INSERT INTO todo (task,status) VALUES ('大笑10声',1)") +conn.commit() diff --git a/vip/kelvinweng/todo/edit_task.tpl b/vip/kelvinweng/todo/edit_task.tpl new file mode 100644 index 0000000..73e9f98 --- /dev/null +++ b/vip/kelvinweng/todo/edit_task.tpl @@ -0,0 +1,10 @@ +

编辑计划: ID = {{no}}

+ + + +
+ + \ No newline at end of file diff --git a/vip/kelvinweng/todo/make_table.tpl b/vip/kelvinweng/todo/make_table.tpl new file mode 100644 index 0000000..bead276 --- /dev/null +++ b/vip/kelvinweng/todo/make_table.tpl @@ -0,0 +1,10 @@ +

这是你接下来要做得事情:

+ +%for row in rows: + + %for col in row: + + %end + +%end +
{{col}}
\ No newline at end of file diff --git a/vip/kelvinweng/todo/new_task.tpl b/vip/kelvinweng/todo/new_task.tpl new file mode 100644 index 0000000..94ec4ce --- /dev/null +++ b/vip/kelvinweng/todo/new_task.tpl @@ -0,0 +1,5 @@ +

添加一个你接下来要做的计划:

+
+ + +
\ No newline at end of file diff --git a/vip/kelvinweng/todo/todo.db b/vip/kelvinweng/todo/todo.db new file mode 100644 index 0000000..f000166 Binary files /dev/null and b/vip/kelvinweng/todo/todo.db differ diff --git a/vip/kelvinweng/todo/todolist.py b/vip/kelvinweng/todo/todolist.py new file mode 100644 index 0000000..13bca28 --- /dev/null +++ b/vip/kelvinweng/todo/todolist.py @@ -0,0 +1,86 @@ +import sqlite3 +from bottle import route,run,template,request,error +import json as js + +@route('/todo') +def todo_list(): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("SELECT id, task FROM todo WHERE status LIKE '1'") + result = c.fetchall() + c.close() + output = template('make_table',rows=result) + return output + +@route('/new',method='GET') +def new_task(): + if request.GET.save: + + new = request.GET.task.strip() + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("INSERT INTO todo (task,status) VALUES (?,?)",(new,1)) + new_id = c.lastrowid + + conn.commit() + c.close() + + return '

成功添加数据,ID为:%s

'%new_id + + else: + return template('new_task.tpl') + +@route('/edit',method="get") +def edit_task(): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.exectue("SELECT task FROM todo WHERE id LIKE ?",(str(no),)) + cur_data = fetchone() + return template('edit_task',old=cur_data,no=no) + +@route('/edit/',method="GET") +def edit_item(no): + if request.GET.save: + edit = request.GET.task.strip() + status = request.GET.status.strip() + + if status == 'open': + status = 1 + else: + status = 0 + + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("UPDATE todo SET task = ?,status = ? WHERE id LIKE ?",(edit,status,no)) + conn.commit() + #c.close() + + return '

成功提交计划 id:%s

'%no + else: + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("SELECT task FROM todo WHERE id LIKE ?",(str(no),)) + cur_data = c.fetchone() + + return template('edit_task',old= cur_data,no=no) + + +@route('/json') +def show_json(json): + conn = sqlite3.connect('todo.db') + c = conn.cursor() + c.execute("SELECT task FROM todo WHERE id LIKE ?",(json,)) + result = c.fetchall() + c.close() + + if not result: + return {'task':'This item number does not exist!'} + else: + #json_result = js.dumps(result[0],ensure_ascii=False) + return {'task':result[0]} + +@error(404) +def mistake404(code): + return 'Sorry,你要的网页不存在!' + +run(reload=True,host='localhost',port='8888') diff --git "a/vip/kelvinweng/\342\200\234\347\224\250 Python \345\274\200\345\217\221\344\270\200\344\270\252 \344\270\252\344\272\272\350\256\241\345\210\222 todolist\342\200\235 \347\254\224\350\256\260.txt" "b/vip/kelvinweng/\342\200\234\347\224\250 Python \345\274\200\345\217\221\344\270\200\344\270\252 \344\270\252\344\272\272\350\256\241\345\210\222 todolist\342\200\235 \347\254\224\350\256\260.txt" new file mode 100644 index 0000000..767a079 --- /dev/null +++ "b/vip/kelvinweng/\342\200\234\347\224\250 Python \345\274\200\345\217\221\344\270\200\344\270\252 \344\270\252\344\272\272\350\256\241\345\210\222 todolist\342\200\235 \347\254\224\350\256\260.txt" @@ -0,0 +1,6 @@ +@route('/todo') + +@bottle.route('/') 表示接下来的自定义函数负责处理网站"/"根目录的请求. + +%for... %end +{{}} 这两种表达都解释为python代码,{{}}代表用实际值替换掉括号中的变量 \ No newline at end of file