添加修改配置文件方法

This commit is contained in:
open-mind 2019-03-18 10:49:34 +08:00
parent 9476979665
commit 1d9f2b21ea
4 changed files with 40 additions and 6 deletions

28
config.py Normal file
View File

@ -0,0 +1,28 @@
import ConfigParser
import psycopg2
class Config():
def __init__(self):
self.cf = ConfigParser.ConfigParser()
self.filename = "recommend.conf"
self.cf.read(self.filename)
def host(self):
return self.cf.get("db","host")
def port(self):
return self.cf.get("db", "port")
def database(self):
return self.cf.get("db", "database")
def user(self):
return self.cf.get("db", "user")
def password(self):
return self.cf.get("db", "password")
def conn(self):
con = psycopg2.connect(host=self.host(), port=self.port(), database=self.database(), user=self.user(),
password=self.password())

View File

@ -1,6 +1,6 @@
[db]
host = 127.0.0.1
host = localhost
port = 5432
database = "oschina"
user = "postgres"
password = "123456"
database = oschina
user = postgres
password = 123456

View File

@ -2,8 +2,11 @@
import sys
import getopt
import psycopg2
import config
con = psycopg2.connect(host = "localhost", port="5432", database='oschina', user='postgres', password='123456')
cf = config.Config()
# con = psycopg2.connect(host = cf.host(), port=cf.port(), database=cf.database(), user=cf.user(), password=cf.password())
con = cf.conn()
def usage():
print(

View File

@ -3,6 +3,7 @@ from numpy import *
import time
import psycopg2
import threading
import config
# 协同过滤推荐算法主要分为:
@ -138,6 +139,8 @@ import threading
# count += 1.0
# self.cost = count / len(user)
cf = config.Config()
con = cf.conn()
class CFThread(threading.Thread):
def __init__(self, threadID, name, handleUs_i):
@ -165,7 +168,7 @@ def readFile(filename):
def getRatings():
data = []
try:
con = psycopg2.connect(host = "localhost", port="5432", database='oschina', user='postgres', password='111111')
# con = psycopg2.connect(host = "localhost", port="5432", database='oschina', user='postgres', password='111111')
cur = con.cursor()
cur.execute('SELECT uid,aid,times from "iTags"."reads" order by aid asc')
curs = cur.fetchall()