Created
September 24, 2020 04:09
-
-
Save nghiahsgs/1ae093539e1d3a9b4cd7668c39f8cdbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from peewee import * | |
from utils import * | |
import requests | |
import json | |
import datetime | |
# host='localhost' | |
# db_name = 'thaygiaoba' | |
# db_user='root' | |
# db_pass='' | |
db = MySQLDatabase(db_name,host=host, user=db_user, passwd=db_pass) | |
class Baiviet(Model): | |
title = CharField() | |
url = CharField() | |
noidung = TextField() | |
linkdich=CharField() | |
idcha=IntegerField() | |
muc = IntegerField() | |
imager = CharField() | |
class Meta: | |
database=db | |
class DataBase_Local(): | |
def get_idcha_Baiviet(self, id): | |
db.connect() | |
kq=Baiviet.select().where(Baiviet.id == id)[0] | |
db.close() | |
return kq.idcha,kq.url,kq.title | |
def insert_Baiviet(self, title, url, noidung, linkdich, idcha, imager): | |
db.connect() | |
if linkdich: | |
instance=Baiviet(title = title, url = url, noidung = noidung, linkdich = linkdich, idcha = idcha, muc = 0, imager = imager) | |
# if instance.save(): | |
# return self.get_id_Baiviet(url) | |
# else: | |
# return 0 | |
instance.save() | |
db.close() | |
def update_Baiviet(self, url, imager='',linkdich=''): | |
db.connect() | |
instance=Baiviet.select().where(Baiviet.url==url)[0] | |
if imager: | |
instance.imager=imager | |
if linkdich: | |
instance.linkdich=linkdich | |
# return instance | |
instance.save() | |
db.close() | |
if __name__=="__main__": | |
Baiviet.create_table() | |
dataBase_Local1=DataBase_Local() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment