Exemplo n.º 1
0
    def activating(self):
        if not self.check_exist(self.phone):
            result = {
                'code': 101,
                'message': conf.result.get(101, '激活用户不存在,请注册后再激活')
            }
        elif get_userdata(self.phone)[2] == 1:
            result = {
                'code': 102,
                'message': conf.result.get(102, '用户已经激活,请直接登录')
            }
        else:
            conn, cur = db.open_sql()
            query = '''	UPDATE USER
						SET STATUS = 1
						WHERE
						phone = {phone}'''.format(phone=self.phone)
            try:
                cur.execute(query=query)
                conn.commit()
                cur.close()
                conn.close()
                result = {'code': 100, 'message': conf.result.get(100, '激活成功')}
            except:
                result = {
                    'code': 103,
                    'message': conf.result.get(103, 'SQL原因,激活失败')
                }

        return result
Exemplo n.º 2
0
def input_userdata(**reg_info):
    conn, cur = db.open_sql()
    print reg_info
    query = '''INSERT INTO USER (
				phone,
				passwd,
				class_type,
				class_num,
				sex
			)
			VALUES
				(
					{phone},
					'{passwd}',
					'{class_type}',
					{class_num},
					'{sex}'
				)
				'''.format(phone=reg_info['en_phone'],
               passwd=md5(reg_info['en_passwd']),
               class_type=reg_info['class_type'],
               class_num=reg_info['class_num'],
               sex=reg_info['sex'])
    try:
        cur.execute(query=query)
        conn.commit()
        cur.close()
        conn.close()
        return True
    except:
        return False
Exemplo n.º 3
0
def get_userdata(phone):
    #以phone为索引拿出用户的所有数据
    data = None
    conn, cur = db.open_sql()
    query = "SELECT * FROM user WHERE phone LIKE {phone}".format(phone=phone)
    try:
        cur.execute(query=query)
        data = cur.fetchone()
    except:
        pass
    conn.commit()
    cur.close()
    conn.close()
    return data  #(18710700957L, 'affaf271b3ebb2db157a04874259cdcb', 1L, 'python', 3L, '?')
Exemplo n.º 4
0
url = 'https://www.cinemablend.com/rss_news_movies.xml'
content = get(url).content
data = xmltodict.parse(content)

struct = {}
i = 0
for article in data['rss']['channel']['item']:
    struct[i] = {
        'title': article['title'],
        'description': re.sub(r'<.*?>', '', article['description'] or ''),
        'date': article['pubDate'],
        'image': article['enclosure']['@url'],
        'link': article['link']
    }
    i += 1

(conn, cursor) = db.open_sql()
cursor.execute('DELETE FROM News')
for id, info in struct.items():
    cursor.execute(
        '''
        INSERT INTO News
        VALUES (%s,%s,%s,%s,%s,%s)
    ''', (id, info['title'], info['description'], info['date'], info['image'],
          info['link']))

conn.commit()
conn.close()

print('cinemablend')