看世界
 
昨日:篇  今日:篇   总帖:篇   会员:
admin
创始人Lv2   
二手房_代码     
# -*- coding: utf-8 -*-
import MySQLdb
import re
import math
import random
from random import choice
import time
from faker import Faker
import os

fake = Faker("zh_CN")
import sys  # reload()之前必须要引入模块

reload(sys)
sys.setdefaultencoding('utf-8')

# 连接MySQL数据库
# db = MySQLdb.connect("127.0.0.1", "root", "jBI5cAhj676BI5%", "house", charset="utf8")



db = MySQLdb.connect("192.168.0.103", "root", "jBI5cAhj676BI5%", "cd_zgxd_net_bak", charset="utf8")




print db

# db = MySQLdb.connect(host="cd.zgxd.net", port=3306, user="cd_zgxd_net",passwd="jBI5cAhj676BI5%",db="cd_zgxd_net",charset="utf8")
cursor = db.cursor()

# for i in range(1,5):

path2 = "D:\\down\\fenlei\\chengdu\\"

AD1 =  path2 +'cdpujiangxian.txt'
AD2 =  path2 +'chenghua.txt'
AD3 =  path2 +'chongzhoushi.txt'
AD4 =  path2 +'dayixian.txt'
AD5 =  path2 +'dujiangyan.txt'
AD6 =  path2 +'gaoxin.txt'
AD7 =  path2 +'jianyangsh.txt'
AD8 =  path2 +'jinniu.txt'
AD9 =  path2 +'jintangxian.txt'
AD10 =  path2 +'Jjinjiang.txt'
AD11 =  path2 +'longquanyi.txt'
AD12 =  path2 +'pengzhoushi.txt'
AD13 =  path2 +'piduqu.txt'
AD14 =  path2 +'qingbaijiangqu.txt'
AD15 =  path2 +'qingyang.txt'
AD16 =  path2 +'qionglaishi.txt'
AD17 =  path2 +'shuangliu.txt'
AD18 =  path2 +'tainfuxinqu.txt'
AD19 =  path2 +'wenjiang.txt'
AD20 =  path2 +'wuhou.txt'
AD21 =  path2 +'xindu.txt'
AD22 =  path2 +'xinjinxian.txt'
LS = [AD1, AD2, AD3, AD4, AD5, AD6, AD7, AD8, AD9, AD10, AD11, AD12, AD13, AD14, AD15, AD16, AD17, AD18, AD19, AD20, AD21, AD22]

# LS = [AD20]

# LS=[L1, L2]
for l in LS:
    sales = ['出售', '急售', '诚意出售', '个人出售', '诚售']
    subways = ['近地铁', '']
    # huxins = ['单间配套','一室一厅','二室一厅','三室一厅','三室二厅']
    huxins = ['单间配套', '一室一厅', '二室一厅']

    huxin_bs = ['三室二厅', '四室二厅']
    spaces_bs = ['131']
    prices_bs = ['60', '63', '65', '68', '70', '75', '78', '82', '85', '86']

    huxin_gg = ['单间配套', '一室一厅', '二室一厅']
    spaces_gg = ['63', '65', '72', '78', '85', '86', '93', '95', '103', '111', '120', '126', '131']
    prices_gg = ['60', '63', '65', '68', '70', '75', '78', '82', '85', '86']



    spaces = ['63', '65', '72', '78', '85', '86', '93', '95', '103', '111', '120', '126', '131']
    prices = ['60', '63', '65', '68', '70', '75', '78', '82', '85', '86']
    loupan = []

    fbnxs = ['房本满二年', '房本满五年', '其他']
    fwlxs = ['公寓', '普通住宅', '商住楼', '商品房']
    fwcxs = ['东', '南', '西', '北']
    zxcds = ['毛坯', '简装', '精装']
    wyzfs = ['是', '否']
    email = []
    mycontact = []

    # sql = "select max(id) from `phome_ecms_info1_data_1`"
    # sql = "select max(id) from `phome_ecms_info1`"
    sql = "select max(id) from `phome_ecms_info1`"

    cursor.execute(sql)
    id_info = cursor.fetchone()

    ClassId = '17'
    # QQ = '527573696'
    Writer = "成都干洗"
    Befrom = "zgxd.net"
    Company = "成都二手房"
    # Phone = '13983000191'
    dq = '成都市'
    print id_info
    if id_info[0] != None:
        g_id = id_info[0]
    else:
        g_id = 0

    for line in open(l):
        lines = line.split(',')

        pattern = re.compile(r',')  # 查找,
        result1 = pattern.findall(line)
        max = len(result1) + 1

        print 'max:' + str(max)

        total = max + g_id

        print "total:" + str(total)
        n = 1
        for ad in lines:
            if re.search('(墅)', ad):

                ad_bs = ad
                huxin = ['三室二厅', '四室二厅','五室二厅'][random.randint(0, 2)]

                space = random.randint(108, 218)  # 面积
                price = str(random.randint(180, 398))  # 低价楼盘
                # dj = round((int(price) / float(space)), 2)
                # smalltext = ad +'超低容积率,品质铸造,赠送面积大,刚改首选'




                g_id = g_id + 1
                dianji_i = random.randint(16858, 39899)
                myarea = ad.split('·')[0]
                loupan = ad.split('·')[-1]
                man = fake.last_name().encode('utf-8') + '先生'  # 男性姓名
                woman = fake.last_name().encode('utf-8') + '女士'  # 女性姓名
                QQ = random.randint(56858, 899989988)
                name = [man, woman]
                name1 = choice(name)
                data = str(fake.date_between(start_date="-2y", end_date="now"))
                phone = str(fake.phone_number())
                sale = choice(sales)
                subway = choice(subways)
                huxin = choice(huxins)  # 户型
                space = random.randint(45, 85)  # 面积
                price = str(random.randint(68, 121))  # 低价楼盘
                dj = round((int(price) / float(space)), 2)
                price = str(price) + '万元'
                fbnx = choice(fbnxs)  # 房本类型price
                fwlx = '别墅'  # 房屋类型
                fwcx = choice(fwcxs)  # 房屋朝向
                zxcd = choice(zxcds)  # 装修程度
                wyzf = choice(wyzfs)  # 唯一住房

                email = fake.email()
                # email = fake.company_email()
                mycontact = str(fake.phone_number())
                address = myarea

                title1 = sale + fwlx
                title2 = sale + loupan
                title3 = loupan + sale

                titles = [title1, title2, title3]

                title = choice(titles)
                i = ad
                newstext = loupan
                detail_title = i
                infotag = fwlx
                detail_keyboard = fwlx

                smalltext = title + '超低容积率,品质铸造,赠送面积大,刚改首选,' + zxcd +','+'房屋朝向:' + fwcx
                titlepic = 'http://www.pictutu.com/img/house/bs/' + str(random.randint(1, 1000)) + '.jpg'

                sql = "insert into `phome_ecms_info1` (`id`, `classid`, `onclick`, `newspath`,`keyboard`, `keyid`, `userid`,`username`,    `checked`,`truetime`,`filename`,            `title`,`newstime`,`titlepic`,`closepl`, `havehtml`, `smalltext`,`myarea`,           `stb`,`copyids`,   `infotags`,`ispic`,   `subway`,                      `huxin`,`space`,`price`,`loupan`,`dj`) values (%s,%s,%s,'%s','%s', '%s', '%s', '%s',              '1', %s, %s,                                    '%s', %s,'%s','0','1',                                    '%s','%s',      '1',  '0', '%s','1',  '%s',                '%s','%s', '%s','%s','%s');" \
                      % (g_id, ClassId, dianji_i, time.strftime("%Y-%m-%d", time.localtime()), fwlx, '', '0', name1, int(time.time()), g_id, title, int(time.time()), titlepic, smalltext, myarea, infotag, subway, huxin, space, price, loupan, dj)
                cursor.execute(sql)

                sql = "insert into `phome_ecms_info1_data_1` (`id`, `classid`, `email`,`mycontact`,`address`,`fbnx`,`fwlx`,`fwcx`,`zxcd`,`wyzf`) values ( %s, %s, '%s',%s,'%s','%s','%s','%s','%s','%s');" % (
                    g_id, ClassId, email, mycontact, loupan, fbnx, fwlx, fwcx, zxcd, wyzf)
                cursor.execute(sql)

            if re.search('(公馆|宿舍)', ad):

                ad_gg =ad
                huxin = ['单间配套', '一室一厅', '二室一厅'][random.randint(0,2)]
                space = random.randint(40, 68)  # 面积
                price = str(random.randint(100, 120))  # 低价楼盘

                # smalltext = ad +'交通便利,成熟地段,商场,银行多,总价低'

                # print "公馆|宿舍::" + huxin,ad,space,price



                g_id = g_id + 1
                dianji_i = random.randint(16858, 39899)
                myarea = ad.split('·')[0]
                loupan = ad.split('·')[-1]
                man = fake.last_name().encode('utf-8') + '先生'  # 男性姓名
                woman = fake.last_name().encode('utf-8') + '女士'  # 女性姓名
                QQ = random.randint(56858, 899989988)
                name = [man, woman]
                name1 = choice(name)
                data = str(fake.date_between(start_date="-2y", end_date="now"))
                phone = str(fake.phone_number())
                sale = choice(sales)
                subway = choice(subways)
                huxin = choice(huxins)  # 户型
                space = random.randint(45, 85)  # 面积
                price = str(random.randint(68, 121))  # 低价楼盘
                dj = round((int(price) / float(space)), 2)
                price = str(price) + '万元'
                fbnx = choice(fbnxs)  # 房本类型price
                fwlx = choice(fwlxs)  # 房屋类型
                fwcx = choice(fwcxs)  # 房屋朝向
                zxcd = choice(zxcds)  # 装修程度
                wyzf = choice(wyzfs)  # 唯一住房

                email = fake.email()
                # email = fake.company_email()
                mycontact = str(fake.phone_number())
                address = myarea
                title1 = sale + huxin
                title2 = sale + loupan
                title3 = loupan + sale
                titles = [title1, title2, title3]
                title = choice(titles)
                i = ad
                newstext = loupan
                detail_title = i
                infotag = fwlx
                detail_keyboard = fwlx

                smalltext = title + '交通便利,成熟地段,商场,银行多,总价低,' + zxcd +','+'房屋朝向:' + fwcx
                titlepic = 'http://www.pictutu.com/img/house/' + str(random.randint(1, 5000)) + '.jpg'


                sql = "insert into `phome_ecms_info1` (`id`, `classid`, `onclick`, `newspath`,`keyboard`, `keyid`, `userid`,`username`,    `checked`,`truetime`,`filename`,            `title`,`newstime`,`titlepic`,`closepl`, `havehtml`, `smalltext`,`myarea`,           `stb`,`copyids`,   `infotags`,`ispic`,   `subway`,                      `huxin`,`space`,`price`,`loupan`,`dj`) values (%s,%s,%s,'%s','%s', '%s', '%s', '%s',              '1', %s, %s,                                    '%s', %s,'%s','0','1',                                    '%s','%s',      '1',  '0', '%s','1',  '%s',                '%s','%s', '%s','%s','%s');" \
                      % (g_id, ClassId, dianji_i, time.strftime("%Y-%m-%d", time.localtime()), fwlx, '', '0', name1,
                         int(time.time()), g_id, title, int(time.time()), titlepic, smalltext, myarea, infotag,
                         subway, huxin, space, price, loupan, dj)
                cursor.execute(sql)

                sql = "insert into `phome_ecms_info1_data_1` (`id`, `classid`, `email`,`mycontact`,`address`,`fbnx`,`fwlx`,`fwcx`,`zxcd`,`wyzf`) values ( %s, %s, '%s',%s,'%s','%s','%s','%s','%s','%s');" % (
                    g_id, ClassId, email, mycontact, loupan, fbnx, fwlx, fwcx, zxcd, wyzf)
                cursor.execute(sql)

                # sql = "INSERT INTO ttt(smalltext,title) VALUES ('%s','%s')" % (smalltext, ad)
                # cursor.execute(sql)

            if not re.search('(公馆|宿舍|墅)', ad):


                huxin = ['二室一厅','三室一厅','三室二厅'][random.randint(0, 2)]
                space = random.randint(55, 120)  # 面积
                price = str(random.randint(115, 180))  # 低价楼盘
                dj = round((int(price) / float(space)), 2)
                smalltext = str(ad + '交通便利,成熟地段,户型合理,朝向好,低总价')
                titlepic = 'http://www.pictutu.com/img/house/' + str(random.randint(1, 5000)) + '.jpg'


                g_id = g_id + 1
                dianji_i = random.randint(16858, 39899)
                myarea = ad.split('·')[0]
                loupan = ad.split('·')[-1]
                man = fake.last_name().encode('utf-8') + '先生'  # 男性姓名
                woman = fake.last_name().encode('utf-8') + '女士'  # 女性姓名
                QQ = random.randint(56858, 899989988)
                name = [man, woman]
                name1 = choice(name)
                data = str(fake.date_between(start_date="-2y", end_date="now"))
                phone = str(fake.phone_number())
                sale = choice(sales)
                subway = choice(subways)
                huxin = choice(huxins)#户型
                space = random.randint(45, 85)#面积
                price = str(random.randint(68, 121))#低价楼盘
                dj = round((int(price) / float(space)),2)
                price = str(price)+'万元'
                fbnx = choice(fbnxs)#房本类型price
                fwlx = choice(fwlxs)#房屋类型
                fwcx = choice(fwcxs)#房屋朝向
                zxcd = choice(zxcds)#装修程度
                wyzf = choice(wyzfs)#唯一住房

                email = fake.email()
                # email = fake.company_email()
                mycontact = str(fake.phone_number())
                address = myarea

                title1 = sale + huxin
                title2 = sale + loupan

                title3 = loupan +sale
                title4 = loupan + huxin +sale
                title5 = huxin +' ' +loupan +  sale
                title6 = sale + loupan+ huxin
                title7 = sale + ad +' ' + huxin



                titles = [title1,title2,title3,title4,title5,title6,title7]
                title = choice(titles)
                i = ad
                newstext = loupan
                smalltext = title + '交通便利,成熟地段,商场,银行多,总价低,可按揭,首次置业首选,' + zxcd +','+'房屋朝向:' + fwcx

                detail_title = i
                infotag = fwlx
                detail_keyboard = fwlx

                sql = "insert into `phome_ecms_info1` (`id`, `classid`, `onclick`, `newspath`,`keyboard`, `keyid`, `userid`,`username`,    `checked`,`truetime`,`filename`,            `title`,`newstime`,`titlepic`,`closepl`, `havehtml`, `smalltext`,`myarea`,           `stb`,`copyids`,   `infotags`,`ispic`,   `subway`,                      `huxin`,`space`,`price`,`loupan`,`dj`) values (%s,%s,%s,'%s','%s', '%s', '%s', '%s',              '1', %s, %s,                                    '%s', %s,'%s','0','1',                                    '%s','%s',      '1',  '0', '%s','1',  '%s',                '%s','%s', '%s','%s','%s');" \
                      % (g_id, ClassId, dianji_i, time.strftime("%Y-%m-%d", time.localtime()), fwlx, '', '0', name1,
                         int(time.time()), g_id, title, int(time.time()), titlepic, smalltext, myarea, infotag,
                         subway, huxin, space, price, loupan, dj)
                cursor.execute(sql)

                sql = "insert into `phome_ecms_info1_data_1` (`id`, `classid`, `email`,`mycontact`,`address`,`fbnx`,`fwlx`,`fwcx`,`zxcd`,`wyzf`) values ( %s, %s, '%s',%s,'%s','%s','%s','%s','%s','%s');" % (
                g_id, ClassId, email, mycontact, loupan, fbnx, fwlx, fwcx, zxcd, wyzf)
                cursor.execute(sql)
















                # sql = "INSERT INTO test(smalltext,title) VALUES ('%s','%s')" % (smalltext, ad)
                # cursor.execute(sql)
db.close()



#                 g_id = g_id + 1
#                 dianji_i = random.randint(16858, 39899)
#
#                 myarea = ad.split('·')[0]
#                 loupan = ad.split('·')[-1]
#                 man = fake.last_name().encode('utf-8') + '先生'  # 男性姓名
#                 woman = fake.last_name().encode('utf-8') + '女士'  # 女性姓名
#                 QQ = random.randint(56858, 899989988)
#                 name = [man, woman]
#                 name1 = choice(name)
#                 data = str(fake.date_between(start_date="-2y", end_date="now"))
#                 phone = str(fake.phone_number())
#                 # dq = '成都' + ad
#
#
#                 sale = choice(sales)
#                 subway = choice(subways)
#                 huxin = choice(huxins)#户型
#                 space = random.randint(45, 85)#面积
#                 price = str(random.randint(68, 121))#低价楼盘
#                 dj = round((int(price) / float(space)),2)
#                 price = str(price)+'万元'
#                 fbnx = choice(fbnxs)#房本类型price
#                 fwlx = choice(fwlxs)#房屋类型
#                 fwcx = choice(fwcxs)#房屋朝向
#                 zxcd = choice(zxcds)#装修程度
#                 wyzf = choice(wyzfs)#唯一住房
#
#                 email = fake.email()
#                 # email = fake.company_email()
#                 mycontact = str(fake.phone_number())
#
#
#
#
#                 address = myarea
#
#
#                 # print wyzf
#                 # print zxcd
#
#                 title1 = sale + huxin
#                 title2 = sale + loupan
#                 title3 = loupan +sale
#
#
#
#                 titles = [title1,title2,title3]
#
#                 title = choice(titles)
#
#
#
#                 i = ad
#
#
#                 newstext = loupan
#
#                 smalltext = newstext
#                 detail_title = i
#
#                 infotag = fwlx
#                 detail_keyboard = fwlx
#
#
#                 # print i
#                 #
#
#                 # sql = "insert into `phome_ecms_info1` (`id`, `classid`, `onclick`, `newspath`,`keyboard`,`keyid`,`useid`,`usename`,`tzid`,`smalltext`) values (%s,%s,%s,'%s','%s',%s,%s,'%s',%s'%s');" %(g_id, ClassId, dianji_i, time.strftime("%Y-%m-%d", time.localtime()),'%s','','','%s','%s','ad')
#                 # cursor.execute(sql)
#                                                                                                                                                                                                                                                                                                                                                                                                   ###############                                   #`truetime`,`filename`               #title#newstime`titlepic``closepl``havehtml`,
#                 sql = "insert into `phome_ecms_info1` (`id`, `classid`, `onclick`, `newspath`,`keyboard`, `keyid`, `userid`,`username`,    `checked`,`truetime`,`filename`,            `title`,`newstime`,`titlepic`,`closepl`, `havehtml`, `smalltext`,`myarea`,           `stb`,`copyids`,   `infotags`,`ispic`,   `subway`,                      `huxin`,`space`,`price`,`loupan`,`dj`) values (%s,%s,%s,'%s','%s', '%s', '%s', '%s',              '1', %s, %s,                                    '%s', %s,'%s','0','1',                                    '%s','%s',      '1',  '0', '%s','1',  '%s',                '%s','%s', '%s','%s','%s');" \
#                       % (g_id, ClassId, dianji_i, time.strftime("%Y-%m-%d", time.localtime()), fwlx, '' ,'0', name1,     int(time.time()), g_id,     title,int(time.time()),'titlepic',                 smalltext,myarea,     infotag,   subway,                   huxin,space,price,loupan,dj)
#                 cursor.execute(sql)
#
#
#
#                 sql = "insert into `phome_ecms_info1_data_1` (`id`, `classid`, `email`,`mycontact`,`address`,`fbnx`,`fwlx`,`fwcx`,`zxcd`,`wyzf`) values ( %s, %s, '%s',%s,'%s','%s','%s','%s','%s','%s');" %(g_id, ClassId, email, mycontact,loupan,fbnx,fwlx,fwcx,zxcd,wyzf)
#                 cursor.execute(sql)
#                 #
#
#                 sql = "insert into `phome_ecms_info1` (`id`, `classid`, `onclick`, `newspath`,`keyboard`, `keyid`, `userid`,`username`,    `checked`,`truetime`,`filename`,            `title`,`newstime`,`titlepic`,`closepl`, `havehtml`, `smalltext`,`myarea`,           `stb`,`copyids`,   `infotags`,`ispic`,   `subway`,                      `huxin`,`space`,`price`,`loupan`,`dj`) values (%s,%s,%s,'%s','%s', '%s', '%s', '%s',              '1', %s, %s,                                    '%s', %s,'%s','0','1',                                    '%s','%s',      '1',  '0', '%s','1',  '%s',                '%s','%s', '%s','%s','%s');"  % (g_id, ClassId, dianji_i, time.strftime("%Y-%m-%d", time.localtime()), fwlx, '', '0', name1, int(time.time()), g_id, title, int(time.time()), 'titlepic', smalltext, myarea, infotag, subway, huxin, space, price, loupan, dj)
#                 cursor.execute(sql)
#
#                 sql = "insert into `phome_ecms_info1_data_1` (`id`, `classid`, `email`,`mycontact`,`address`,`fbnx`,`fwlx`,`fwcx`,`zxcd`,`wyzf`) values ( %s, %s, '%s',%s,'%s','%s','%s','%s','%s','%s');" % (g_id, ClassId, email, mycontact, loupan, fbnx, fwlx, fwcx, zxcd, wyzf)
#                 cursor.execute(sql)
#
#                 try:
#
#                     db.commit()
#                     n += 1
#                 except:
#                     db.rollback()
#                     print("insert error")
# db.close()
# print '插入完成' + str(max) + '记录'
print '当前已经完成的ID:' + str(total)
print "当前进程工作目录 : %s" % os.getcwd()
"D:\Program Files (x86)\Anaconda2\python.exe" "D:/Program Files/JetBrains/PyCharm 2017.3.3/helpers/pydev/二手房出售_价格面积分类.py"
 0  已被阅读了18次  楼主 2018-10-20 15:31:00
回复列表

回复:二手房_代码

LOOK官方站 联系站长
Powered by Look博客