def __init__(self): wordpress_detector = WPDetector() joomla_detector = JOOMLADetector() squarespace_detector = SquareSpaceDetector() detectors = [wordpress_detector, joomla_detector, squarespace_detector] self._mydb = MyDB() self._mydb.connect() self._model = Model(detectors)
def load_Kind(self): # Connect DataBase ('MyLibrary') myDB = MyDB() # DB Query Execute results = myDB.kind_query() # Close DataBase myDB.close() return results # 検索結果を返す
def getAdjprc(dt): dbWind = MyDB('WIND_SQL') self._conn = pymssql.connect(server="192.168.1.181", user="******", password="******", database="wind") querysql = ''' declare @trddt varchar(8) select @trddt = '%s' select trade_days tradedate,rank() over(order by trade_days) cnt into #calendar from wind.dbo.AshareCalendar where s_info_exchmarket ='SSE' select * ,convert(float,(preclsprc0-xd)/xr) preclsprc into #stktrd from ( SELECT left(e.[s_info_windcode], 6) AS stkcode , c1.tradedate ,e.s_dq_close preclsprc0 , (ISNULL(bonus_share_ratio, 0) + ISNULL(conversed_ratio, 0) + 1)*ISNULL(consolidate_split_ratio, 1) AS xr , ISNULL(cash_dividend_ratio, 0) AS xd FROM wind.dbo.ashareeodprices e join #calendar c0 on e.trade_dt = c0.tradedate join #calendar c1 on c1.cnt = c0.cnt + 1 left join wind.dbo.ASHAREEXRIGHTDIVIDENDRECORD AS P on p.[s_info_windcode]=e.[s_info_windcode] and p.ex_date=c1.tradedate WHERE SUBSTRING(e.[s_info_windcode], 1, 1) IN ('0', '3', '6') and c1.tradedate = @trddt )a select e.trade_dt tradedate ,(case when S_INFO_WINDCODE='000016.SH' then 'IH' when s_info_windcode='000300.SH' then 'IF' when s_info_windcode='000905.SH' then 'IC' end) stkcode ,convert(float,S_DQ_CLOSE) preclsprc into #idxtrd from wind.dbo.AINDEXEODPRICES e join #calendar c0 on e.trade_dt = c0.tradedate join #calendar c1 on c1.cnt = c0.cnt + 1 where S_INFO_WINDCODE in ('000016.SH' ,'000300.SH', '000905.SH' ) and c1.tradedate = @trddt ''' % dt dbWind.Execute(querysql) querysql = '''select stkcode,preclsprc from #idxtrd order by stkcode''' dfidx = dbWind.FetchAll(querysql) dfidx.set_index('stkcode', inplace=True) print(dfidx['preclsprc']) return dfidx['preclsprc']
def Load_OriginalMenu(self, k_code): # Connect DataBase ('MyLibrary') myDB = MyDB() # DB Query Execute results = myDB.original_menu_query(k_code) # Close DataBase myDB.close() print(results) # for Debug return results # 検索結果を返す
def load_Data(self): # Connect DataBase ('MyLibrary') myDB = MyDB('MyLibrary') # DB Query Execute results = myDB.query('SELECT a_id, author_name ' \ 'FROM author_table order by 1;') # Close DataBase myDB.close() return results # 検索結果を返す
def load_Data(self): # Connect DataBase ('MyLibrary') myDB = MyDB('MyLibrary') # DB Query Execute results = myDB.query('SELECT b_id, b_name, genre_table.g_name, author_table.author_name ' \ 'FROM book_table, genre_table, author_table ' \ 'where book_table.g_code = genre_table.g_code and ' \ 'book_table.a_id = author_table.a_id;') # Close DataBase myDB.close() return results # 検索結果を返す
def main(): # 创建数据库实例 test_db = MyDB(user='******', passwd='0516', db='test_py') # Create c_params = (('Benzema', 28, 'M'), ('Bale', 26, 'M'), ('Ronaldo', 31, 'M')) last_row_id = test_db.insert('person', c_params, field_list=['name', 'age', 'gender'], is_many=True) print(last_row_id) # 1 # Retrieve result_set = test_db.select('SELECT * FROM person WHERE age<28;') print(result_set) # ((2L, u'Bale', 26L, u'M'),) # Update update_sql = 'UPDATE person SET age=%s WHERE name=%s;' u_params = (29, 'Benzema') update_rows_cnt = test_db.update(update_sql, u_params) print(update_rows_cnt) # 1 # Delete delete_rows_cnt = test_db.delete("DELETE FROM person WHERE age>30;") print(delete_rows_cnt) # 1
def __init__(self, h, p, d, u, pwd): MyDB.__init__(self, h, p, d, u, pwd)
import threading import time import twitterScraper # Local imports from MyDB import MyDB import matplotlib.pyplot as plt from datetime import datetime import logging import tweetHandler import pandas as pd # Initialise database and log db = MyDB() logging.basicConfig(filename='logs/queue_log.log', level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s') # Placeholder to record max wait before all Threads can terminate safely maxRate = 0 # Global boolean to control threads running = True def getTweets(topic, rate, amount): # Wait before starting time.sleep(rate) while running: # Scrape tweets raw = twitterScraper.scrapeTweets(topic, amount)
# print album album_id = album[0] album_url = album[7] print 'start to gather album ' + str(album_id) # print album_url # continue getPhotos(album_url,pre,album_id) db.changeAlbumIf(1,album_id) host = 'localhost' root = 'root' pwd = '' db = 'meinv' chset = 'utf8' db = MyDB(host,root,pwd,db,chset) # saveTopics() # saveAlbums() # 采集只有一页的图集列表 # pre = 'http://www.meinv369.com' # album_url = 'http://www.meinv369.com/siwa/' # topic_id = 5 # getOnePageAlbum(album_url,topic_id,pre) # url = 'http://www.meinv369.com/mm/mm767.html' # getPhoto(url) # html = getPics_module.getHtmlProxies(url) # # print html # # exit()
# Filename: getDouban_tags.py import getDouban_module from MyDB import MyDB host = 'localhost' root = 'root' pwd = '' db = 'movies' chset = 'utf8' db = MyDB(host,root,pwd,db,chset) url = 'http://movie.douban.com/tag/?view=type' pre = 'http://movie.douban.com/tag/' html = getDouban_module.getHtml(url) tagsHtml = getDouban_module.getTagsHtml(html) # print tagsHtml i = 1 j = 0 for tagHtml in tagsHtml: # f = file('tagUrl.txt','a+') # f.write('\n------------' + str(i) + '------------------\n') tagUrl = getDouban_module.getUrl(tagHtml) for tu in tagUrl: # f.write('\n' + tu[1] + '\n') # f.write('\n' + pre + tu[1] + '\n') kind_id = i tag_name = tu[1] tag_url = pre + tu[1] db.saveTagUrl(kind_id, tag_name, tag_url) j = j + 1
class Controller(object): def __init__(self): self._mydb = MyDB() self._mydb.connect() self._model = Model() def read_xml(self, xml_file_path): """ :param xml_file_path: xml file with relevant data :return:list. record from db: platform,domain,version and date of last detection. """ try: mydoc = minidom.parse(xml_file_path) items = mydoc.getElementsByTagName('item') formdata = {} for item in items: formdata[item.attributes['name'].value] = item.firstChild.data domain = formdata.get("domain") cache = formdata['usecache'] return self.check_platform(domain, cache) except Exception as e: print(e) def check_platform(self, domain, cache, platform=None): """ :param platform:string. the user know platform is the website, he looks for the version. :param cache: boolean. weather user want to use cache or not. :param domain: string. the domain that the user want to check. if user want record from cache then check if it exist in db if exist then check if the last date is relevant else run check_platform method in model :return:string. record(line) from db. """ try: # user don't want record from db at all if not cache: if len(self._mydb.select(domain)) > 0: self._mydb.delete(domain) if platform is None: sol = self._model.check_platform(domain) else: sol = self._model.check_platform(domain, platform) if not sol[0]: return sol[1] else: self._mydb.insert_data(domain=domain, platform=sol[0], version=sol[1]) return self._mydb.select(domain) # user want record from db else: record = self._mydb.select(domain) # record not found, run this method again with no cache-check if not record: cache = False if platform is None: return self.check_platform(domain, cache) else: return self.check_platform(domain, cache, platform) # record found else: # if date is relevant(last check less then 6 month) if self._check_date(domain, record): return record # date is not relevant, run this method again with no cache-check else: cache = False if platform is None: return self.check_platform(domain, cache) else: return self.check_platform(domain, cache, platform) except Exception as e: print(e) def _check_date(self, domain, record): """ :param domain:string. the domain of the specific record. :param record:tuple. record for specific domain from db. :return: boolean. true if the date is relevant(less then 6 month from last check) or false if it is not relevant """ try: today = str(datetime.date.today()).split("-") today_year = today[0] today_month = today[1] date = str(record[0][4]).split(" ") date_t = date[0].split("-") year = date_t[0] month = date_t[1] if int(year) < int(today_year): self._mydb.delete(domain) return False elif int(year) == int(today_year): if int(today_month) > int(month) + 6: self._mydb.delete(domain) return False return True except Exception as e: print(e)
# Filename: getDouban_tags.py import getDouban_module from MyDB import MyDB host = 'localhost' root = 'root' pwd = '' db = 'movies' chset = 'utf8' db = MyDB(host, root, pwd, db, chset) url = 'http://movie.douban.com/tag/?view=type' pre = 'http://movie.douban.com/tag/' html = getDouban_module.getHtml(url) tagsHtml = getDouban_module.getTagsHtml(html) # print tagsHtml i = 1 j = 0 for tagHtml in tagsHtml: # f = file('tagUrl.txt','a+') # f.write('\n------------' + str(i) + '------------------\n') tagUrl = getDouban_module.getUrl(tagHtml) for tu in tagUrl: # f.write('\n' + tu[1] + '\n') # f.write('\n' + pre + tu[1] + '\n') kind_id = i tag_name = tu[1] tag_url = pre + tu[1] db.saveTagUrl(kind_id, tag_name, tag_url) j = j + 1
def getCourseEvents( events, users ): ###################################################################### # returns: void # parameters: refernce to event list, list of users db = MyDB() conn = db.connect() c = conn.cursor() # http://stackoverflow.com/questions/283645/python-list-in-sql-query-as-parameter placeholder= '?' placeholders= ', '.join(placeholder for unused in users) query = """SELECT c.days, c.startDate, c.endDate, c.startTime, c.endTime FROM Courses c INNER JOIN CoursesProfs cp ON cp.cid = c.prof INNER JOIN Profs p ON p.email = cp.pid WHERE p.email IN (%s)""" % placeholders results = c.execute(query, users) for row in results: # print row # format data daysArr = list(row[0]) startDate = datetime.datetime.strptime(row[1], "%x"); endDate = datetime.datetime.strptime(row[2], "%x"); startTime = str(row[3]) if len(startTime) == 3: #need four digits startTime = '0'+startTime startTime = datetime.time( int(startTime[0:2]), int(startTime[2:4])) endTime = str(row[4]) if len(endTime) == 3: #need four digits endTime = '0'+endTime endTime = datetime.time( int(endTime[0:2]), int(endTime[2:4])) # add course span for each day for letter in daysArr: #for each day of that class curDate = getFirstDateForDay(startDate, letter) #returns a datetime while (curDate <= endDate): #add all spans for that day within the window date = curDate.date() # print type(date) # print type(startTime) year = date.year month = date.month day = date.day shour = startTime.hour sminute = startTime.minute ehour = endTime.hour eminute = endTime.minute eventDateTimeStart = datetime.datetime.combine(datetime.date(year, month, day), datetime.time( shour, sminute)) eventDateTimeEnd = datetime.datetime.combine(datetime.date(year, month, day), datetime.time( ehour, eminute)) newSpan = Span( eventDateTimeStart, eventDateTimeEnd ) events.append(newSpan) curDate = curDate + datetime.timedelta(days=7) # days in a week
from flask import Flask, Response, send_file, render_template, request, session, make_response, redirect, url_for, flash, g, jsonify import sys import atexit sys.path.append("./docker") import client sys.path.append("./database") from MyDB import MyDB myDB = MyDB() flask_app = Flask('flaskapp') # captain: UserID flask_app.secret_key = 'thisisatest' session = {'UserID': 0} # To add new user in the database @flask_app.route('/new-user', methods = ['POST']) def adduser(): if request.method == 'POST': ID = request.form['username'] Pswd = request.form['password'] resp = myDB.add_new_user(ID, Pswd) if resp == False: return jsonify(resp) else: session['UserID'] = int(resp) return jsonify(True) else: return 'Wrong method' # return Response("working on new user block\n", mimetype = 'text/plain')
def __init__(self): self._mydb = MyDB() self._mydb.connect() self._model = Model()
from MyDB import MyDB myDB = MyDB() try: print(myDB.add_new_user("username123", "password")) userID = myDB.login_user("username123", "password") print(userID) print(myDB.login_user("username123", "password2")) print(myDB.get_credits(userID)) myDB.update_credits(userID, 10) print(myDB.get_credits(userID)) #myDB.delete_user(userID) print(myDB.login_user("username", "password")) except Exception as e: print(e) myDB.close_connection()