Exemple #1
0
    def accept(self, parent_id, name, stat_info, arc_flag, fullPath = None):
        is_dir = 0
        if stat.S_ISDIR(stat_info[stat.ST_MODE]):
            is_dir = 1
        ext = self.getExt(name)
        self.file_no = self.file_no + 1
        self.c.execute("""
            INSERT INTO directory(snapshot, no, parent, name, extension, size, is_dir, arc_status, mdate)
            VALUES (%d, %d, %s, %s, %s, %d, %d, %d, '%s')
        """ % (self.disk_id, self.file_no, parent_id, DbConn.quote(name), DbConn.quote(ext), 
               stat_info[stat.ST_SIZE], is_dir, arc_flag, time.strftime("%Y%m%d%H%M%S", time.localtime(stat_info[stat.ST_MTIME])))
        )
        id = self.c.lastrowid

        # Update UI with status
        self.feedbackObject.feedback(self.file_no);

        # Bookkeeping
        if arc_flag == Const.ARC_IN_ARCHIVE:
            if stat.S_ISDIR(stat_info[stat.ST_MODE]): 
                self.numArcDirectories = self.numArcDirectories + 1
            else: 
                self.numArcFiles = self.numArcFiles + 1
        else:
            if stat.S_ISDIR(stat_info[stat.ST_MODE]): 
                self.numDirectories = self.numDirectories + 1
            else: 
                self.numFiles = self.numFiles + 1
                if arc_flag == Const.ARC_IS_ARCHIVE:
                    self.numArchives += 1

        return int(id)
Exemple #2
0
def start():
    x = DbType.SYBASE
    logger = JLogger("/workspace/outme.log", "test")
    db_temp = DbConn(x, "sa", "myPassword", "dbsybase", "5000", "tempdb",
                     logger)
    db_master = DbConn(x, "sa", "myPassword", "dbsybase", "5000", "master",
                       logger)

    pipeline(db_master, db_temp)
Exemple #3
0
 def insertNew(self, fullPath, fileInfo):
     path = self.getInVoumePath(fullPath)
     self.additions.append(path)
     dir = self.resolverApi.getIdByPath(self.disk_id, os.path.dirname(path))
     sql = """
         INSERT INTO directory(snapshot, no, parent, name, extension, size, is_dir, arc_status, mdate)
         VALUES (%d, %d, %s, %s, %s, %d, %d, %d, '%s')
     """ % (self.disk_id, 0, dir[0]["id"], DbConn.quote(fileInfo.name), DbConn.quote(self.getExt(fileInfo.name)), 
            fileInfo.size, fileInfo.isDir, 0, fileInfo.mtime)
     if self.debugLevel & DbUpdateDumper.DEBUG_SQL:
         print sql
     self.c.execute(sql)
Exemple #4
0
def movie_detail(year):
    db = DbConn()
    sql = "select moviecd from boxoffice2 where dailydate between TO_DATE('" + str(
        year) + "/01/01', 'YYYY/MM/DD') and TO_DATE('" + str(
            year) + "/12/31', 'YYYY/MM/DD') group by moviecd"
    print(sql)
    cd_list = db.execute(sql)
    db.disconnect()

    for movie_cd in cd_list:
        insert_moviedetail(movie_cd[0])

    print(len(cd_list), "개 인서트 끝~~~~")
Exemple #5
0
def load_user(userid):
    try:
        return User(
            DbConn.DbConn(app.config['MYSQL_USERNAME'],
                          app.config['MYSQL_PASSWORD'],
                          app.config['MYSQL_DB']), int(userid))
    except InvalidUserError, e:
        return None
 def addFileCategory(self, fileId, categoryId, value = None, timeStamp = None):
     if timeStamp == None: 
         timeStamp = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
     cursor = self.connection.getCursor()
     cursor.execute("""\
         INSERT INTO category_map(cat_id, obj_id, value, tstamp) 
         VALUES (%d, %d, %s, '%s')
     """ % (categoryId, fileId, DbConn.quote(value), timeStamp))
     self.connection.commit()
Exemple #7
0
    def reparent(self, fullPath, fileInfo, match):
        path = self.getInVoumePath(fullPath)

#        if fileRec["is_dir"]: path += "/"
        self.updates.append((
            self.resolverApi.getFilePath(match["id"]) + ["", "/"][match["is_dir"]], 
            path + ["", "/"][fileInfo.isDir]
        ))

        dir = self.resolverApi.getIdByPath(self.disk_id, os.path.dirname(path))
        sql = "UPDATE directory SET parent=%d, name=%s, size=%d, mdate='%s' WHERE id=%d" % (dir[0]['id'], DbConn.quote(fileInfo.name), fileInfo.size, fileInfo.mtime, match['id'])
        if self.debugLevel & DbUpdateDumper.DEBUG_SQL:
            print sql
        self.c.execute(sql)
    start_id = int(args.start)
  end_id = int(args.end)
  print "ID range: " + str(start_id) + " to " + str(end_id)
  if start_id >= end_id:
    print "ID range is empty, halting."
    sys.exit(0)

  if int(args.per_minute) < 1 or int(args.per_minute) > 60:
    print "Users per minute must be between 1 and 60, inclusive"
    sys.exit(0)

  list_insert_queue = DbConn.DbInsertQueue(db, table='mal_anime_lists', fields=[
    'user_id',
    'anime_id',
    'started',
    'time',
    'finished',
    'status',
    'score',
    'episode'
  ]).update('started=VALUES(started), time=VALUES(time), finished=VALUES(finished), status=VALUES(status), score=VALUES(score), episode=VALUES(episode)')

  mal_statuses_to_int = {
    'Unknown': 0,
    'Watching': 1,
    'Completed': 2,
    'On-Hold': 3,
    'Dropped': 4,
    'Plan to Watch': 6
  }

  sleep_time = 60 / int(args.per_minute)
Exemple #9
0
import requests
import time
from pathlib import Path
import sys
from DbConn import *

db = DbConn()

sql = """
SELECT *
FROM BOXOFFICE
"""

result = db.execute(sql)

print(type(result), result)
from sklearn.externals import joblib
from DbConn import *
import pandas as pd
import numpy as np

db = DbConn()

# 총 관객수 예측 모델
# model = joblib.load('C:/Users/user/SweetBox/test/max_people.pkl')
model = joblib.load(
    'C:/Users/user/SweetBox/test/1000_500_200_100_voting_model.pkl')

# 예측할 영화 정보 초기 값
MOVIE_NAME = "극한직업"
PRODUCER = "(주)어바웃필름"
DIRECTOR = "이병헌"
ACTOR1 = "류승룡"
ACTOR2 = "이하늬"
ACTOR3 = "진선규"
ACTOR4 = "이동휘"
SCREEN = "1553"

# parameters ----------------

# producer
PROD_MAX = 0
PROD_AVG = 0
prod_sql = """
SELECT max(MAX_AUDIACC) AS PROD_MAX, avg(MAX_AUDIACC) AS PROD_AVG 
FROM MOVIE2 
WHERE PRODNM = :PRODUCER
Exemple #11
0
#**********************************
#START PROGRAM RUN
#**********************************

# My Secret Key
private_secret = os.urandom(64)

# Create the kernel and learn AIML files
kernel = aiml.Kernel()
kernel.learn("std-startup.xml")
kernel.respond("load aiml b")

chat_users = SessionManager.Session()
agre_bot_commands = CommandDetector.AgreBotCommands()
db_conn = DbConn.AgreBotDbConnection(1)

open_sessions(kernel, chat_users)
print('after session load')
print(chat_users._session_dict)
print(kernel._sessions)
print('entering program')

# Connecting to Twitch IRC by passing credentials and joining a certain channel
s = socket.socket()
s.connect((HOST, PORT))
s.send("PASS " + PASS + "\r\n")
s.send("NICK " + NICK + "\r\n")
s.send("JOIN " + channel_name + " \r\n")
#creating DB Connection
Exemple #12
0

def dict_dot(a, b):
    return sum(a[key] * b[key] for key in a if key in b)


def dict_corr(a, b):
    keys = list(a.viewkeys() | b.viewkeys())
    return numpy.corrcoef([a.get(x, 0) for x in keys],
                          [b.get(x, 0) for x in keys])[0, 1]


config = configobj.ConfigObj(
    infile=open('/home/shaldengeki/llAnimuBot/config.txt', 'r'))
db = DbConn.DbConn(username=config['DB']['llBackup']['username'],
                   password=config['DB']['llBackup']['password'],
                   database=config['DB']['llBackup']['name'])

# assemble a list of topics.
sat_db = DbConn.DbConn(username=config['DB']['llAnimu']['username'],
                       password=config['DB']['llAnimu']['password'],
                       database=config['DB']['llAnimu']['name'])
sats = [
    eti.Topic(db, topic_id).load()
    for topic_id in sat_db.table('sats').fields('ll_topicid').where(
        completed=1).order('ll_topicid ASC').list(valField='ll_topicid')
]

# assemble a dict of all users and their post counts in each SAT.
users = {}
for sat in sats:
Exemple #13
0
def insert_moviedetail(moviecd):
    db = DbConn()

    url = MOVIE_DETAIL_URL + '?key=' + API_KEY + '&movieCd=' + str(moviecd)
    data = requests.get(url).json()

    movie_info_list = data['movieInfoResult']['movieInfo']

    insert_query = '''
    INSERT INTO movie (movieCd,movieNm,movieNmEn,prdtYear,showTm,openDt,prdtStatNm,typeNm,nations,genre,genreSub,director,actors1,actors2,actors3,actors4,audits,prodCd,prodNm,distCd,distNm,staffs)
    VALUES(:movieCd,:movieNm,:movieNmEn,:prdtYear,:showTm,:openDt,:prdtStatNm,:typeNm,:nations,:genre,:genreSub,:director,:actors1,:actors2,:actors3,:actors4,:audits,:prodCd,:prodNm,:distCd,:distNm,:staffs)
    '''
    select_query = "SELECT * FROM movie WHERE MOVIECD = :MOVIECD"

    #변수 조건
    actor1 = movie_info_list['actors'][0]['peopleNm'] if len(
        movie_info_list['actors']) > 0 else ''
    actor2 = movie_info_list['actors'][1]['peopleNm'] if len(
        movie_info_list['actors']) > 1 else ''
    actor3 = movie_info_list['actors'][2]['peopleNm'] if len(
        movie_info_list['actors']) > 2 else ''
    actor4 = movie_info_list['actors'][3]['peopleNm'] if len(
        movie_info_list['actors']) > 3 else ''

    nations = movie_info_list['nations'][0]['nationNm'] if len(
        movie_info_list['nations']) > 0 else ''

    genre = movie_info_list['genres'][0]['genreNm'] if len(
        movie_info_list['genres']) > 0 else ''
    genreSub = movie_info_list['genres'][1]['genreNm'] if len(
        movie_info_list['genres']) > 1 else ''

    director = movie_info_list['directors'][0]['peopleNm'] if len(
        movie_info_list['directors']) > 0 else ''

    audits = movie_info_list['audits'][0]['watchGradeNm'] if len(
        movie_info_list['audits']) > 0 else ''

    openDt = datetime.strptime(movie_info_list['openDt'], '%Y%m%d')
    prodCd = ""
    prodNm = ''
    distCd = ''
    distNm = ''

    if len(movie_info_list['companys']) > 0:
        for n in movie_info_list['companys']:
            if n['companyPartNm'] == '제작사':
                prodCd = n['companyCd']
                prodNm = n['companyNm']
                break
        for n in movie_info_list['companys']:
            if n['companyPartNm'] == '배급사':
                distCd = n['companyCd']
                distNm = n['companyNm']
                break

    staffs = movie_info_list['staffs'][0]['peopleNm'] if len(
        movie_info_list['staffs']) > 0 else ''

    query_params = {
        'movieCd': movie_info_list['movieCd'],
        'movieNm': movie_info_list['movieNm'],
        'movieNmEn': movie_info_list['movieNmEn'],
        'prdtYear': movie_info_list['prdtYear'],
        'showTm': movie_info_list['showTm'],
        'openDt': openDt,
        'prdtStatNm': movie_info_list['prdtStatNm'],
        'typeNm': movie_info_list['typeNm'],
        'nations': nations,
        'genre': genre,
        'genreSub': genreSub,
        'director': director,
        'actors1': actor1,
        'actors2': actor2,
        'actors3': actor3,
        'actors4': actor4,
        'audits': audits,
        'prodCd': prodCd,
        'prodNm': prodNm,
        'distCd': distCd,
        'distNm': distNm,
        'staffs': staffs
    }

    select_result = db.execute(select_query, {"MOVIECD": moviecd})

    if len(select_result) == 0:
        # print(insert_query, query_params)
        db.execute(insert_query, query_params)

    print(movie_info_list['movieNm'], "작업 완료. -----")
    db.disconnect()
 def findByTypeAndName(self, type, name):
     cursor = self.connection.getCursor()
     cursor.execute("SELECT * FROM category WHERE type=%d AND name=%s" % (type, DbConn.quote(name)))
     if cursor.rowcount != 1: return None
     return cursor.fetchone()
Exemple #15
0
 def findByParentIdAndName(self, diskId, parentId, name):
     cursor = self.connection.getCursor()
     cursor.execute("SELECT * FROM directory WHERE snapshot=%d AND parent=%d AND name=%s" % (diskId, parentId, DbConn.quote(name)))
     return cursor.fetchall()
Exemple #16
0
def before_request():
    g.db = DbConn.DbConn(app.config['MYSQL_USERNAME'],
                         app.config['MYSQL_PASSWORD'], app.config['MYSQL_DB'])
Exemple #17
0
10 == 아파트매매 실거래 상세 자료
11 == 아파트(도로명) 목록
12 == 아파트(법정동) 목록
13 == 아파트 기본정보
"""

TEST = False

cnt       = 0
total_cnt = 17529

api_type = '13'
data_ymd = YESTERDAY_YMD

if TEST == False:
    data_code_list = DbConn.select_data_code ( api_type )

    for data_code in data_code_list :
        print(str(cnt)+ "/" + str(total_cnt) + " : " + data_code[0])

        json_obj = PublicDataApi.get_json_data_from_public_data_api( api_type, data_code[0], data_ymd )

        if ( api_type == '13' ) :
            MakeCsvFile.save_json_to_csv_file( api_type, data_code[0], data_ymd, json_obj['item'], 1 )
            MakeCsvFile.save_json_to_log_file( api_type, data_code[0], data_ymd, json_obj['item'], 1 )

        else :
            print("totalCount : ", json_obj['totalCount'])


            # api 호출 결과가 1건 이상일 경우에만 CSV/DB 저장
#   try:
#     if sproc:
#       if sproc[0] in name_proc.keys():
#         name_proc[sproc[0]] = name_proc[sproc[0]].append(sproc[1])
#       else:
#         name_proc[sproc[0]] = [sproc[1]]
#   except AttributeError:
#     print("Not found: {0}".format(sproc[0]))

# print(len(name_proc.keys()))
# print("".join(txt))
from Nums import DbType
from Utils import JLogger
x = DbType.SYBASE
logger = JLogger("/workspace/outme.log", "test")
db = DbConn(x, "sa", "myPassword", "dbsybase", "5000", "tempdb", logger)
# statement = """
# CREATE TABLE mockData(
#   pid int not null,
#   img image
# )
# """
# DataUtils.uploadImage(db.conn, "/workspace/samples/img.png",
# statement = """
# SELECT * FROM blobtest
# """
# queryList = db.queryToList(statement)
# for y in queryList:
#   print(y)

# statement = """
Exemple #19
0
def insert_boxoffice(showrange):
    db = DbConn()
    url = BOX_OFFICE_URL+"?key="+API_KEY+"&targetDt="+showrange
    data = requests.get(url).json()
    
    boxOfficeResult = data['boxOfficeResult']
    showRange = boxOfficeResult['showRange']
    dailyBoxOfficeList = boxOfficeResult['dailyBoxOfficeList']

    insert_query = """
    INSERT INTO boxOffice
    (showrange, rnum, rank, rankinten, rankoldandnew, moviecd, movienm, opendt, salesamt, salesshare, salesinten, saleschange, salesacc, audicnt, audiinten, audichange, audiacc, scrncnt, showcnt)
    VALUES (:showrange, :rnum, :rank, :rankinten, :rankoldandnew, :moviecd, :movienm, :opendt, :salesamt, :salesshare, :salesinten, :saleschange, :salesacc, :audicnt, :audiinten, :audichange, :audiacc, :scrncnt, :showcnt)
    """
    select_query = "SELECT * FROM BOXOFFICE WHERE SHOWRANGE = :SHOWRANGE AND MOVIECD = :MOVIECD"


    for i in dailyBoxOfficeList: # 하루에 1위~10위 데이터 들어있음
        salesInten = i['salesInten']
        openDt = i['openDt']
        if len(openDt) < 3:
            continue

        audiInten = i['audiInten']
        rnum = i['rnum']
        movieCd = i['movieCd']
        audiAcc = i['audiAcc']
        showCnt = i['showCnt']
        audiCnt = i['audiCnt']
        salesAmt = i['salesAmt']
        movieNm = i['movieNm']
        rank = i['rank']
        audiChange = i['audiChange']
        rankInten = i['rankInten']
        scrnCnt = i['scrnCnt']
        rankOldAndNew = i['rankOldAndNew']
        salesChange = i['salesChange']
        salesAcc = i['salesAcc']
        salesShare = i['salesShare']
        
        query_params = {
            'showrange' : showRange,
            'rnum' : rnum,
            'rank' : rank,
            'rankinten' : rankInten,
            'rankoldandnew' : rankOldAndNew,
            'moviecd' : movieCd,
            'movienm' : movieNm,
            'opendt' : openDt,
            'salesamt' : salesAmt,
            'salesshare' : salesShare,
            'salesinten' : salesInten,
            'saleschange' : salesChange,
            'salesacc' : salesAcc,
            'audicnt' : audiCnt,
            'audiinten' : audiInten,
            'audichange' : audiChange,
            'audiacc' : audiAcc,
            'scrncnt' : scrnCnt,
            'showcnt' : showCnt
        }

        select_result = db.execute(select_query, {"SHOWRANGE": showRange, "MOVIECD": movieCd})

        if len(select_result) == 0:
            db.execute(insert_query, query_params)
            # print(showRange, movieNm,'성공적으로 DB에 입력했슴')
        # else :
        #     print(showRange, movieNm,'는 안대요 안대~!')
    print(showrange, "작업 완료. -----")
    db.disconnect()
Exemple #20
0
def insert_boxoffice(showrange):
    db = DbConn()
    url = BOX_OFFICE_URL + "?key=" + API_KEY + "&targetDt=" + str(showrange)
    data = requests.get(url).json()

    # showRange = data['boxOfficeResult']['showRange']
    dailyBoxOfficeList = data['boxOfficeResult']['dailyBoxOfficeList']
    dailydate = datetime.strptime(showrange, '%Y%m%d').strftime('%Y-%m-%d')

    insert_query = """
    INSERT INTO boxOffice2
    (dailydate, rnum, mrank, rankinten, rankoldandnew, moviecd, movienm, opendt, salesamt, salesshare, salesinten, saleschange, salesacc, audicnt, audiinten, audichange, audiacc, scrncnt, showcnt)
    VALUES (TO_DATE(:dailydate, 'YYYY-MM-DD'), :rnum, :mrank, :rankinten, :rankoldandnew, :moviecd, :movienm, TO_DATE(:opendt, 'YYYY-MM-DD'), :salesamt, :salesshare, :salesinten, :saleschange, :salesacc, :audicnt, :audiinten, :audichange, :audiacc, :scrncnt, :showcnt)
    """
    select_query = "SELECT * FROM BOXOFFICE2 WHERE dailydate = TO_DATE(:dailydate, 'YYYY-MM-DD') AND MOVIECD = :MOVIECD"

    for i in dailyBoxOfficeList:  # 하루에 1위~10위 데이터 들어있음

        p = re.compile('[0-9]')
        movieCd_re = p.findall(i['movieCd'])
        print(i['movieCd'], movieCd_re)

        if len(movieCd_re) != 8:
            continue

        openDt = i['openDt']
        if len(openDt) < 3:
            continue

        query_params = {
            'dailydate': dailydate,
            'rnum': i['rnum'],
            'mrank': i['rank'],
            'rankinten': i['rankInten'],
            'rankoldandnew': i['rankOldAndNew'],
            'moviecd': i['movieCd'],
            'movienm': i['movieNm'],
            'opendt': openDt,
            'salesamt': i['salesAmt'],
            'salesshare': i['salesShare'],
            'salesinten': i['salesInten'],
            'saleschange': i['salesChange'],
            'salesacc': i['salesAcc'],
            'audicnt': i['audiCnt'],
            'audiinten': i['audiInten'],
            'audichange': i['audiChange'],
            'audiacc': i['audiAcc'],
            'scrncnt': i['scrnCnt'],
            'showcnt': i['showCnt']
        }
        # print(query_params)
        select_result = db.execute(select_query, {
            "dailydate": dailydate,
            "MOVIECD": i['movieCd']
        })

        if len(select_result) == 0:
            db.execute(insert_query, query_params)
            # print(showRange, movieNm,'성공적으로 DB에 입력했슴')
        # else :
        #     print(showRange, movieNm,'는 안대요 안대~!')

    print(showrange, "작업 완료. -----")
    db.disconnect()
    def import_mal_profiles(self):
        '''
    Processes the MAL profile scraping queue.
    '''
        if (datetime.datetime.now(tz=pytz.utc) -
                self.info['last_run_time']) < datetime.timedelta(hours=1):
            return
        self.info['last_run_time'] = datetime.datetime.now(tz=pytz.utc)
        self.daemon.log.info("Processing MAL profile queue.")

        mal_session = myanimelist.session.Session()
        import_requests = self.dbs['animurecs'].table('users').fields(
            'id', 'mal_username',
            'last_import').where('mal_username IS NOT NULL').where(
                'last_import_failed = 0').order('last_import ASC').list()
        entries_to_add = []
        entry_insert_queue = DbConn.DbInsertQueue(
            self.dbs['animurecs'], 'anime_lists',
            ['user_id', 'anime_id', 'time', 'status', 'score', 'episode'
             ]).ignore(True)

        requested_ids = map(lambda r: int(r['id']), import_requests)
        broken_ids = []

        for request in import_requests:
            # process MAL profile import request.
            self.daemon.log.info("Processing MAL profile for user ID " +
                                 str(request['id']) + ".")
            try:
                anime_list = mal_session.anime_list(
                    request['mal_username']).load()
            except myanimelist.media_list.InvalidMediaListError as e:
                self.daemon.log.error("Invalid MAL username provided: " +
                                      request['mal_username'] +
                                      ". Marking as broken and skipping.")
                broken_ids.append(int(request['id']))
                continue
            curr_time = datetime.datetime.now(tz=pytz.timezone(
                self.daemon.config['timezone'])).strftime('%Y-%m-%d %H:%M:%S')
            for anime in anime_list.list:
                if anime_list.list[anime]['score'] is None:
                    anime_list.list[anime]['score'] = 0
                entry_insert_queue.queue({
                    'user_id':
                    request['id'],
                    'anime_id':
                    int(anime.id),
                    'time':
                    pytz.timezone(self.daemon.config['timezone']).localize(
                        anime_list.list[anime]['last_updated']).strftime(
                            '%Y-%m-%d %H:%M:%S'),
                    'status':
                    self.mal_statuses_to_int[anime_list.list[anime]['status']],
                    'score':
                    anime_list.list[anime]['score'],
                    'episode':
                    anime_list.list[anime]['episodes_watched']
                })
        # flush insert queue.
        entry_insert_queue.flush()

        # update last-import time and broken usernames.
        if requested_ids:
            self.dbs['animurecs'].table('users').set(
                last_import=datetime.datetime.now(
                    tz=pytz.timezone(self.daemon.config['timezone'])).strftime(
                        '%Y-%m-%d %H:%M:%S')).where(id=requested_ids).update()
        if broken_ids:
            self.dbs['animurecs'].table('users').set(
                last_import_failed=1).where(id=broken_ids).update()
        self.daemon.log.info("Inserted entries for " +
                             str(len(requested_ids)) + " users.")