#!/user/bin/python
# -*- coding: utf-8 -*-
"""
"""
import re
import json
from xlog import xwrite
from collections import defaultdict
import sys
import base64
def write_json(count_id,str):
data = {"id": count_id, "name": str}
with open(‘/Users/v_qinyuan/Documents/python.project/shop/json_str.json‘,‘a‘) as f:
print(json.dump(data,f,ensure_ascii=False))#将获取的内容已规定格式输出
def read_josn(name):#https://blog.csdn.net/whjkm/article/details/81159888
file_path = ‘/Users/v_qinyuan/Documents/python.project/shop/json_str.json‘
f = open(file_path, ‘r‘)
for line in f:
json_data = json.loads(line)
if json_data[‘name‘] == name:
id = json_data[‘id‘]
return id
def read_josn_num(name):#https://blog.csdn.net/whjkm/article/details/81159888
for i in name:
file_path = ‘/Users/v_qinyuan/Documents/python.project/shop/json_str.json‘
f = open(file_path, ‘r‘)
for line in f:
json_data = json.loads(line)
if json_data[‘id‘] == i:
size = json_data[‘name‘]
print(size)
def input_raw(txt):
arr_num = []
for i in txt:
arr_num.append(read_josn(i))
print(arr_num)
def each_line(path):#解析原始文件
count_id = 0
file_path = path
p1 = re.compile(r‘size(.*?)(1)‘)
f = open(file_path, ‘r‘)
for each_line in f:
res = p1.search(each_line)
if res is not None:
count_id += 1
a = res.groups()[0]
if a != None:
str = a[0:1]
print(count_id,str)
#write_json(count_id,str)
def encode_base64(txt):
bytes_url = txt.encode("utf-8")
str_url = base64.b64encode(bytes_url) # 被编码的参数必须是二进制数据
return str_url
def decode_base64(txt):
str_url = base64.b64decode(txt).decode("utf-8")
print(str_url)
if __name__ == ‘__main__‘:
#print(each_line("/Users/v_qinyuan/Documents/python.project/shop/dist_ch.txt"))
#read_josn()
in_ra = input_raw(‘上庄‘)
en_ba = encode_base64(‘上庄‘)
print(en_ba)
#read_josn_num([1779, 2481, 477, 1091, 2361, 701, 1223, 2993])
#encode_base64(‘‘)
瞎写随笔1--各种解析