<commit_before>from mysql import mysql
from mysql import DB_Exception
from shutil import copyfile
from display_api import get_user_id
from display_api import display_data_type
from PIL import Image
import os
import os.path
import shutil
import bcrypt
import json
import tornado
import time
import random
from tornado.escape import xhtml_escape
from tornado.web import MissingArgumentError
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
import httplib2
from apiclient import discovery
import datetime
from dataAccessObjects import UserDao

class ArgumentUtil():
    def __init__(self,requestHandler):
        self.handler = requestHandler

    def getArgument(self,name):
        rawArg = self.handler.get_argument(name)
        return xhtml_escape(rawArg)

    def getArguments(self):
        raise NotImplementedError("The getArgument() is not implemented.")

class UserArgumentsUtil(ArgumentUtil):
    def __init__(self,requestHandler):
        super().__init__(requestHandler)

    def getArguments(self):
        userInfo = {}
        userInfo['user_name'] = self.getArgument('username')
        userInfo['user_password'] = self.getArgument('password')
        return userInfo

class UserEditArgumentsUtil(ArgumentUtil):
    def getCurUser(self):
        return self.handler.get_current_user()

    def getArguments(self):
        userInfo = {}
        userInfo['user_name'] = self.getCurUser()
        userInfo['old_password'] = self.getArgument('old_password')
        userInfo['new_password'] = self.getArgument('password')
        return userInfo

class UploadArgumentsUtil(ArgumentUtil):
    def getArguments(self):
        uploadData = {}
        uploadData['file_type'] = self.getArgument('data_type')
        uploadData['start_date'] = self.getArgument('start_date')
        uploadData['end_date'] = self.getArgument('end_date')
        uploadData['start_time'] = self.getArgument('start_time')
        uploadData['end_time'] = self.getArgument('end_time')
        uploadData['display_time'] = self.getArgument('display_time')
        return uploadData
#
def add_like_count(db, target_id):
    try:
        sql = ""
        if target_id[0:4]=="imge":
            sql = ("UPDATE image_data SET img_like_count=img_like_count+1 WHERE img_id='" + str(target_id) + "'")
        elif target_id[0:4]=="text":
            sql = ("UPDATE text_data SET text_like_count=text_like_count+1 WHERE text_id='" + str(target_id) + "'")
        else :
            return 0
        db.cmd(sql)
        
        return 1
    except:
        return 0
        
#find the current displaying schedule
def find_now_schedule(db):
    try:
        sql = "SELECT sche_target_id FROM schedule WHERE sche_is_used=0 ORDER BY sche_sn ASC LIMIT 1"
        pure_result = db.query(sql)
        if len(pure_result):
            return str(pure_result[0][0])
        else:
            return 0
    except:
        return -1
#
def add_now_like_count():
    try:
        return_msg = {}
        return_msg["result"] = "fail"
        db = mysql()
        db.connect()

        #find image or text id from current schedule
        target_id = find_now_schedule(db)
        if target_id==0:
            db.close()
            return_msg["error"] = "can not find current schedule"
            return return_msg
            
        #add like count
        if add_like_count(db, target_id)==0:
            db.close()
            return_msg["error"] = "can not add like count"
            return return_msg

        return_msg["result"] = "success"
        return return_msg
                <commit_msg>modify function find_now_schedule<commit_after>from mysql import mysql
from mysql import DB_Exception
from shutil import copyfile
from display_api import get_user_id
from display_api import display_data_type
from PIL import Image
import os
import os.path
import shutil
import bcrypt
import json
import tornado
import time
import random
from tornado.escape import xhtml_escape
from tornado.web import MissingArgumentError
from oauth2client import client
from oauth2client import tools
from oauth2client.file import Storage
import httplib2
from apiclient import discovery
import datetime
from dataAccessObjects import UserDao
from dataAccessObjects import ScheduleDao

class ArgumentUtil():
    def __init__(self,requestHandler):
        self.handler = requestHandler

    def getArgument(self,name):
        rawArg = self.handler.get_argument(name)
        return xhtml_escape(rawArg)

    def getArguments(self):
        raise NotImplementedError("The getArgument() is not implemented.")

class UserArgumentsUtil(ArgumentUtil):
    def __init__(self,requestHandler):
        super().__init__(requestHandler)

    def getArguments(self):
        userInfo = {}
        userInfo['user_name'] = self.getArgument('username')
        userInfo['user_password'] = self.getArgument('password')
        return userInfo

class UserEditArgumentsUtil(ArgumentUtil):
    def getCurUser(self):
        return self.handler.get_current_user()

    def getArguments(self):
        userInfo = {}
        userInfo['user_name'] = self.getCurUser()
        userInfo['old_password'] = self.getArgument('old_password')
        userInfo['new_password'] = self.getArgument('password')
        return userInfo

class UploadArgumentsUtil(ArgumentUtil):
    def getArguments(self):
        uploadData = {}
        uploadData['file_type'] = self.getArgument('data_type')
        uploadData['start_date'] = self.getArgument('start_date')
        uploadData['end_date'] = self.getArgument('end_date')
        uploadData['start_time'] = self.getArgument('start_time')
        uploadData['end_time'] = self.getArgument('end_time')
        uploadData['display_time'] = self.getArgument('display_time')
        return uploadData
#
def add_like_count(db, target_id):
    try:
        sql = ""
        if target_id[0:4]=="imge":
            sql = ("UPDATE image_data SET img_like_count=img_like_count+1 WHERE img_id='" + str(target_id) + "'")
        elif target_id[0:4]=="text":
            sql = ("UPDATE text_data SET text_like_count=text_like_count+1 WHERE text_id='" + str(target_id) + "'")
        else :
            return 0
        db.cmd(sql)
        
        return 1
    except:
        return 0
        
#find the current displaying schedule
def find_now_schedule(db):
    try:
        with ScheduleDao() as scheduleDao:
            next_schedule = scheduleDao.getNextSchedule()
        # return sche_target_id
        if next_schedule != None:
            return str(next_schedule['sche_target_id'])
        else:
            return 0
    except:
        return -1
#
def add_now_like_count():
    try:
        return_msg = {}
        return_msg["result"] = "fail"
        db = mysql()
        db.connect()

        #find image or text id from current schedule
        target_id = find_now_schedule(db)
        if target_id==0:
            db.close()
            return_msg["error"] = "can not find current schedule"
            return return_msg
            
        #add like count
        if add_like_count(db, target_id)==0:
            db.close()
            return_msg["error"] = "can not add like count"
            return return_msg

        return_msg["result"] = "success"
        return return_msg
                
{'fraction_non_alphanumeric': 0.092051352089593, 'fraction_numerical': 0.00518983884184649, 'mean_word_length': 2.878707627118644, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7168806', 'n_tokens_mistral': 2082, 'n_tokens_neox': 2054, 'n_words': 516}