-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
70 lines (53 loc) · 2.12 KB
/
database.py
File metadata and controls
70 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import xlrd
import os
import sys
import datetime
import click
import random
import time
import threading
from flask import Flask, render_template,session,redirect,url_for,flash,make_response,request, flash
from flask_wtf import FlaskForm
from wtforms import SubmitField, TextAreaField,StringField,SelectField
from wtforms.validators import DataRequired
from flask_sqlalchemy import SQLAlchemy
WIN = sys.platform.startswith('win')
if WIN:
prefix = 'sqlite:///'
else:
prefix = 'sqlite:////'
app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
basedir = os.path.abspath(os.path.dirname(__file__))
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'secret string')
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL', prefix + os.path.join(app.root_path, 'data.db'))
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Wenke(db.Model):
id = db.Column(db.Integer, primary_key=True)
paiming = db.Column(db.Integer,default=0)
name = db.Column(db.String(120))
toudangrenshu = db.Column(db.Integer,default=0)
toudangxian = db.Column(db.Integer,default=0)
toudangmingci = db.Column(db.Integer,default=0)
class Like(db.Model):
id = db.Column(db.Integer, primary_key=True)
paiming = db.Column(db.Integer,default=0)
name = db.Column(db.String(120))
toudangrenshu = db.Column(db.Integer,default=0)
toudangxian = db.Column(db.Integer,default=0)
toudangmingci = db.Column(db.Integer,default=0)
workbook = xlrd.open_workbook(r'D:\Python\Python37-32\python_excel\like.xlsx')
sheet2 = workbook.sheet_by_name('Sheet1')
for num1 in range(1257):
paiming = sheet2.cell(num1,0).value
name = sheet2.cell(num1,1).value
toudangrenshu = sheet2.cell(num1,2).value
toudangxian = sheet2.cell(num1,3).value
toudangmingci = sheet2.cell(num1,4).value
newlike = Like(paiming=paiming,name=name,toudangrenshu=toudangrenshu,toudangxian=toudangxian,toudangmingci=toudangmingci)
db.session.add(newlike)
db.session.commit()
print(num1)
print('over')