Skip to content

Instantly share code, notes, and snippets.

View jackeyGao's full-sized avatar
Focusing

JG jackeyGao

Focusing
View GitHub Profile
@jackeyGao
jackeyGao / middlware.py
Last active April 3, 2020 07:56
show message via django messages when django session is expired
from django.utils.deprecation import MiddlewareMixin
from django.contrib import messages
from django.utils import timezone
from django.conf import settings
from django.utils.functional import cached_property
class StateMiddleware(MiddlewareMixin):
@classmethod
@jackeyGao
jackeyGao / eval.py
Last active June 28, 2019 01:13
Python convert a string to f-string
>>> hello = 'Hello'
>>> world = 'world!'
>>> str = '{hello} {world}'
>>> str.format(**locals())
# or
>>> str = '{hello.upper()} {world.upper()}'
>>> eval(f'''f"{str}"''')
'HELLO WORLD!'
@jackeyGao
jackeyGao / crawl_songci_parse.py
Last active December 21, 2023 08:49
全宋词爬虫解析脚本
# -*- coding: utf-8 -*-
'''
File Name: parser.py
Author: JackeyGao
mail: gaojunqi@outlook.com
'''
import sys
import random
import time
import requests
@jackeyGao
jackeyGao / update_to_update_parse.py
Created August 25, 2016 02:41
UPDATE TO UPDATE
KEYS = {
"1": "id",
"2": "name",
"3": "class",
"4": "score",
}
def dict_to_sqlstring(d):
string = ""
@jackeyGao
jackeyGao / del_to_insert_parse.py
Created August 25, 2016 02:40
DELETE TO INSERT
with open('del.sql', 'r') as f:
insert = ""
for i in f.readlines():
if i.startswith('### DELETE FROM'):
insert = insert.strip(',') + ';'
if insert != ';':
print insert
insert = "INSERT INTO"
@jackeyGao
jackeyGao / functional_programming.py
Created August 10, 2016 07:21
函数式编程初试
# -*- coding: utf-8 -*-
'''
File Name: client.py
Author: JackeyGao
mail: gaojunqi@outlook.com
Created Time: 三 8/10 10:35:02 2016
'''
import json
import sys
from collections import defaultdict
@jackeyGao
jackeyGao / output
Last active August 11, 2016 05:11
Python 树状字典
{
"A": {
"AA": {
"AAA": "Hello"
}
},
"B": {
"BB": {
"BBB": "world"
@jackeyGao
jackeyGao / filter_args.py
Created July 8, 2016 06:48
Django 获取查询参数通用函数
def get_args(request, excludes):
args = {}
for i in request.GET:
if i in excludes:
continue
value = request.GET.getlist(i)
if len(value) == 1:
args[i] = value[0]
else:
args[i] = value
@jackeyGao
jackeyGao / guangdian.py
Last active July 8, 2016 06:42
响应广电总局 Python 编码规范
# -*- 编码: 万国码-八 -*-
导入 系统
定义 输出:
系统.标准输出.写入("你好, 世界!")
如果 __模块名__ == '__主体__':
输出()