添加修改配置文件方法
This commit is contained in:
parent
9476979665
commit
1d9f2b21ea
|
@ -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())
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue