a
This commit is contained in:
parent
1cb45c1a9f
commit
7fa7a1c09d
57
myapp/1.py
57
myapp/1.py
@ -1,57 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
import sys
|
|
||||||
import copy
|
|
||||||
|
|
||||||
|
|
||||||
def read_files(filename):
|
|
||||||
all = dict()
|
|
||||||
with open(filename, 'r') as f:
|
|
||||||
data = f.read().strip()
|
|
||||||
for line in data.split("\n"):
|
|
||||||
try:
|
|
||||||
all[line.split("======")[-1]] = line.split("======")[0]
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return all
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# 要读的文件写入其中,多条记录用,分割,注意不要用全角的","
|
|
||||||
filenames = ("a.txt", "b.txt")
|
|
||||||
|
|
||||||
# 记录所有数据,标题为字典的key,URL为字典的值(如果有价格,可以将(url,价格)作为字典的values)
|
|
||||||
new_data = dict()
|
|
||||||
# 这个列表记录有交集的标题,会在数据统计完毕从new_data中删除
|
|
||||||
intersection = list()
|
|
||||||
for filename in filenames:
|
|
||||||
data = read_files(filename)
|
|
||||||
for key in data.keys():
|
|
||||||
if key in new_data:
|
|
||||||
intersection.append(key)
|
|
||||||
else:
|
|
||||||
new_data[key] = data[key]
|
|
||||||
# 将全部数据做一个备份,可能会有其他需求用到
|
|
||||||
all_data = copy.deepcopy(new_data)
|
|
||||||
with open('out1.txt', "a+") as f:
|
|
||||||
for item in intersection:
|
|
||||||
all_data.pop(item)
|
|
||||||
#将重复的内容写入out1.txt
|
|
||||||
temp = f"{new_data[item]}===={item}\n"
|
|
||||||
f.write(temp)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
out = list()
|
|
||||||
with open('out.txt', "a+") as f:
|
|
||||||
for key in all_data:
|
|
||||||
# 这种写法是python3.6后支持的,版本低的话可以写temp="{0}===={1}".format(all_data[key],key)
|
|
||||||
temp = f"{all_data[key]}===={key}\n"
|
|
||||||
out.append(temp)
|
|
||||||
f.write(temp)
|
|
||||||
|
|
||||||
print(out)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
@ -1,24 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from flask import Flask
|
|
||||||
from flask.ext.mail import Mail
|
|
||||||
from flask.ext.sqlalchemy import SQLAlchemy
|
|
||||||
from werkzeug.utils import import_string
|
|
||||||
|
|
||||||
mail = Mail()
|
|
||||||
db = SQLAlchemy()
|
|
||||||
blueprints = [
|
|
||||||
'myapp.main:main',
|
|
||||||
'myapp.admin:admin',
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def create_app(config):
|
|
||||||
app = Flask(__name__)
|
|
||||||
app.config.from_object(config)
|
|
||||||
mail.init_app(app)
|
|
||||||
db.init_app(app)
|
|
||||||
|
|
||||||
for bp_name in blueprints:
|
|
||||||
bp = import_string(bp_name)
|
|
||||||
app.register_blueprint(bp)
|
|
||||||
return app
|
|
@ -1,5 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from flask import Blueprint
|
|
||||||
|
|
||||||
admin = Blueprint('admin', __name__, url_prefix='/admin')
|
|
||||||
from myapp.admin import views
|
|
@ -1 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
@ -1,5 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from flask import Blueprint
|
|
||||||
main=Blueprint('main',__name__)
|
|
||||||
from myapp.main import views
|
|
@ -1,7 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from __future__ import absolute_import
|
|
||||||
from myapp.main import main
|
|
||||||
|
|
||||||
@main.route('/')
|
|
||||||
def index():
|
|
||||||
return '<h>Hello world ,I am main</h>'
|
|
@ -1 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
12
run.py
12
run.py
@ -1,12 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from werkzeug.wsgi import DispatcherMiddleware
|
|
||||||
from werkzeug.serving import run_simple
|
|
||||||
from myapp import create_app
|
|
||||||
import config
|
|
||||||
|
|
||||||
release_app = create_app('config.release')
|
|
||||||
debug_app = create_app('config.debug')
|
|
||||||
|
|
||||||
app = DispatcherMiddleware(release_app, {'/test': debug_app})
|
|
||||||
|
|
||||||
run_simple("0.0.0.0", 5000, app, use_reloader=True, use_debugger=True)
|
|
Loading…
x
Reference in New Issue
Block a user