python bottle解决跨域问题

同意跨域

1
2
3
4
5
6
7
8
9
from bottle import route, run, template, Bottle, response

app = Bottle()

@app.hook('after_request')
def enable_cors():
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'

git基本操作

clone远端项目

1
2
git clone https://github.com/jquery/jquery.git
git clone username@host:/path/to/repository

远程主机

1
2
3
4
# 克隆版本库的时候,所使用的远程主机自动被Git命名为origin
git remote -v
# 将你的仓库连接到某个远程服务器
git remote add origin <server>

提交,拉取

1
2
3
4
5
# 注意,分支写法是<来源地>:<目的地>
# git fetch <远程主机名> <分支名>,使用"远程主机名/分支名"读取。比如origin主机的master:origin/master
git fetch origin master
git pull <远程主机名> <远程分支名>:<本地分支名>
git push <远程主机名> <本地分支名>:<远程分支名>

spark 提交任务 python pyspark

spark-submit

1
spark-submit --master yarn --deploy-mode cluster --queue q1 --num-executors 1 scripy.py

pyspark

1
2
3
4
5
6
7
8
9
10
11
12
13
def process(rows):
content = ""
for row in rows:
content += b64encode(row.url)
return [content]

conf = SparkConf().setAppName('PoliceHive2Xml')
spark_context = SparkContext(conf=conf)
hive_context = HiveContext(spark_context)
sql = "select * from table where dayno=20170807 limit 1000"
data_frame = hive_context.sql(sql)
hdfs_filepath = get_hdfs_filepath(table_name, zip_file_name)
data_frame.mapPartitions(process).saveAsTextFile(hdfs_filepath)

python执行shell命令

popen

1
2
3
4
5
6
7
8
9
10
11
def _command_execute(command_s):
"""执行命令,例如command_s=['ls', '-al']"""
sp = Popen(command_s, stdout=PIPE, stderr=STDOUT, close_fds=True)
output_content = ''
for line in iter(sp.stdout.readline, b''):
output_content += line

if len(output_content) > 1024 * 4:
break
sp.wait()
return int(sp.returncode), output_content

python xml,html转义字符

xml转义字符

1
2
3
4
5
6
7
from xml.sax.saxutils import escape
def xmlescape(data):
if data is None:
data = ''
elif not isinstance(data, str):
data = str(data)
return escape(data, entities={"'": "&apos;", '"': "&quot;"})

html转义字符

1
2
3
4
5
6
7
8
9
10
11
def html_escape(s):
htmlcodes = (
('&', '&amp;'),
("'", '&#39;'),
('"', '&quot;'),
('>', '&gt;'),
('<', '&lt;'),
)
for code in htmlcodes:
s = s.replace(code[0], code[1])
return s