Esempio n. 1
0
 def engine(self):
     """Main method to run the class"""
     while True:
         self.user_input = self.command_corrector(input('> '))
         self.full_season_info = data.copy()
         if self.user_input[0] == 'watch':
             if len(self.user_input) == 1:
                 self.watch()
             else:
                 episode_quantity = self.user_input[1]
                 self.watch(quantity=episode_quantity)
         elif self.user_input[0] == 'precise':
             if len(self.user_input) == 1:
                 self.precise()
             else:
                 season_number = self.user_input[1]
                 episode_number = self.user_input[2]
                 self.absolute_precision(season_number, episode_number)
         elif self.user_input[0] == 'go':
             self.watch(quantity=1, full_random=1)
         elif self.user_input[0] == 'help':
             helper()
         elif self.user_input[0] == 'history':
             self.look_back(self.user_input[1])
         elif self.user_input[0] == 'display':
             self.display(self.user_input[1])
         elif self.user_input[0] == 'delete':
             self.delete_record(self.user_input[1])
         elif self.user_input[0] == 'switch':
             self.switch()
         elif self.user_input[0] == 'clear':
             sp.call('cls', shell=True)
         elif self.user_input[0] == 'exit':
             sys.exit()
Esempio n. 2
0
def test_helper(capsys):
    helper.helper()
    captured_stdout, captured_stderr = capsys.readouterr()
    assert captured_stderr == ""
    assert captured_stdout == "USAGE\n    ./105torus opt a0 a1 a2 a3 a4 n\n"\
    "DESCRIPTION\n    opt       method option:\n                   "\
    "1 for the bisection method\n                   2 for Newton's method\n"\
    "                   3 for the secant method\n    a[0-4]    coefficients"\
    " of the equation\n    n         precision (the application of the"\
    " polynomial to the solution should be smaller than 10^-n)\n"
Esempio n. 3
0
def handle_response(command, response):

    specials = ['publish', 'discard', 'logout', 'help']
    immutable = 'show'

    # get response
    data = response.json()
    # clean up response, so user can read
    pretty_print = json.dumps(data, indent=4, sort_keys=False)

    # write the response to output file
    with open(out_file, 'w') as f:
        f.write(pretty_print)

    f.close()

    print("Wrote response content to %s" % out_file)

    status = str(response.status_code)

    print("Status code :%s" % status)

    # if response is 200 (good) make sure we don't tell user to publish if they run publish,discard,logout,help,or show(s)
    if (status == '200' and (command not in specials)
            and (immutable not in command)):
        print("\n\tRemember to publish changes via: \"./cpr.sh publish\"\n")
        return '200'
    elif status == '409':
        print(
            "\n\tProblem with locks. Make sure you are publishing and terminating sessions properly.\n"
        )
        return '409'
    elif status == '404':
        print("\nI don't recognize the command: %s\n" % (command))
        helper(command)
        return '404'
    elif status == '400':
        print("\nError or missing command parameters. Refer to output.txt\n")
        return '400'
    elif status == '401':
        print("\nSession Expired. You need to login.\n")
        session_fd = open(session_file, 'w')
        session_fd.truncate()
        session_fd.close()
        return '401'
    else:
        print('Response: %s (Check output.txt for more)' %
              (response.status_code))
        return None
Esempio n. 4
0
def main(args=None):
    parser = argparse.ArgumentParser(description='Status check facility')

    parser.add_argument("-i",
                        "--input",
                        type=str,
                        dest='input',
                        help='Input DATA/MC folder')
    parser.add_argument("-r",
                        "--resubmit",
                        dest='resubmit',
                        default=False,
                        action='store_true',
                        help='HTCondor flag to resubmit failed jobs')
    parser.add_argument("-v",
                        "--verbose",
                        dest='verbose',
                        default=False,
                        action='store_true',
                        help='run in high verbosity mode')

    opts = parser.parse_args(args)
    status_helper = helper.helper()

    pars = {
        "input": opts.input,
        "resubmit": opts.resubmit,
        "verbose": opts.verbose
    }

    status_helper.status_preselection_stats(pars)
Esempio n. 5
0
    def __init__(self, classes, maxSteps, maxNonChangingSteps, parameters):
        self.helper = helper()
        self.CLASSES = classes
        self.MAX_STEPS = maxSteps
        self.MAX_NONCHANGING_STEPS = maxNonChangingSteps

        self.LEARNING_RATE = parameters[0]
        self.SHRINKAGE = parameters[1]
        self.NUM_LAYERS = int(parameters[2])
        self.NEURONS_PER_LAYER = parameters[
            3]  #NEURONSPERLAYER is a list of the number of neurons that exist per layer - excluding the bias neuron.
        self.batchSize = parameters[4]
        self.MOMENTUM = parameters[5]
        random.seed()
        self.parameters = [
            self.LEARNING_RATE, self.SHRINKAGE, self.NUM_LAYERS,
            self.NEURONS_PER_LAYER, self.SIGMOID.__name__, self.batchSize,
            self.MOMENTUM
        ]

        self.maxWeights = []
        for k in range(len(self.NEURONS_PER_LAYER) - 1):
            self.maxWeights.append(
                np.ones(shape=(self.NEURONS_PER_LAYER[k] + 1,
                               self.NEURONS_PER_LAYER[k + 1])))
        for k in range(len(self.NEURONS_PER_LAYER) - 1):
            for i in range(len(self.maxWeights[k])):
                for j in range(len(self.maxWeights[k][i])):
                    #Starting weights are set randomly, dependant on the number of inputs. Compare lecture 17, neuralnetworks slide 10.
                    self.maxWeights[k][i][j] = random.uniform(
                        -1, 1) / (self.NEURONS_PER_LAYER[k + 1])**0.5
    def get_all_knowledge_level_features(self, inp):

        k = inp
        x = hp.helper()

        user_df = pd.read_csv("../../data/processed/users.csv")
        user_df['Id'] = user_df['Id'].astype(int)

        posts_df = pd.read_csv("../../data/processed/posts.csv")
        posts_df['Id'] = posts_df['Id'].astype(int)

        c, nc = x.get_user_id(k)
        c_label = [1 for i in c]
        nc_label = [0 for i in nc]

        c_df = pd.DataFrame({'OwnerUserId': c, 'label': c_label})
        nc_df = pd.DataFrame({'OwnerUserId': nc, 'label': nc_label})
        feature_df = c_df.append(nc_df, ignore_index=True)

        li = list(range(k))

        k_df = posts_df.groupby('OwnerUserId').filter(
            lambda x: x['CreationDate'].count() >= k)
        k_df = k_df.sort_values(
            ['OwnerUserId', 'CreationDate'],
            ascending=[True,
                       True]).groupby('OwnerUserId').nth(li).reset_index()

        feature_df['acc_ans_rep'] = feature_df.apply(
            lambda row: self.get_accepted_answerer_reputation(
                row, posts_df, user_df, k_df),
            axis=1)
        feature_df['max_rep_ansrr'] = feature_df.apply(
            lambda row: self.get_max_reputation_answerer(
                row, posts_df, user_df, k_df),
            axis=1)
        feature_df['num_que_answered'] = feature_df.apply(
            lambda row: self.get_num_questions_answered(
                row, posts_df, user_df, k_df),
            axis=1)
        feature_df['rep_questioner'] = feature_df.apply(
            lambda row: self.get_rep_questioner(row, posts_df, user_df, k_df),
            axis=1)
        feature_df['num_answers_recvd'] = feature_df.apply(
            lambda row: self.get_num_answers_recvd(row, posts_df, user_df, k_df
                                                   ),
            axis=1)

        feature_df['rep_answerers'] = feature_df.apply(
            lambda row: self.get_rep_answerers(row, posts_df, user_df, k_df),
            axis=1)
        feature_df['rep_co_answerers'] = feature_df.apply(
            lambda row: self.get_rep_co_answerers(row, posts_df, user_df, k_df
                                                  ),
            axis=1)

        print(feature_df.shape)
        #print(feature_df.tail(20))

        return feature_df
Esempio n. 7
0
    def LoginBaidu(self):
        if str(self.text_loginname.text()).strip(
        ) != '' and self.text_password.text() != '':
            self.btnOk.setText(u'请耐心等待...')
            helperModel = helper(None)
            if not helperModel.recordsExistAndLasted():

                try:
                    if self.Login("http://wwww.baidu.com"):
                        self.close()
                        loaderWindow = Ui_MainWindow(
                            str(self.text_loginname.text()).strip(),
                            str(self.text_password.text()),
                            parent=None)
                        loaderWindow.exec_()

                    else:
                        QMessageBox.warning(self, u'登录失败', u'可能是用户名或密码有问题',
                                            QMessageBox.Yes)
                        self.btnOk.setText(u"再次登录")
                except:
                    raise
                    self.btnOk.setText(u"再次登录")
                    return
            else:
                self.close()
                loaderWindow = Ui_MainWindow(str(
                    self.text_loginname.text()).strip(),
                                             str(self.text_password.text()),
                                             parent=None)
                loaderWindow.exec_()
Esempio n. 8
0
 def __init__(self,lmdb_path):
   if not os.path.isfile(lmdb_path):
     assert 0,'Invalid .pkl lmdb {}\n'.format(lmdb_path)
   
   #note: we need to define svg class prior to loading it
   helps = helper()
   self.svgdb = helps.load(lmdb_path)
Esempio n. 9
0
    def __init__(self, classes, maxSteps, maxNonChangingSteps,
                 parametersGiven):
        self.helper = helper()
        self.CLASSES = classes
        self.MAX_STEPS = maxSteps
        self.MAX_NONCHANGING_STEPS = maxNonChangingSteps
        self.LEARNING_RATE = parametersGiven[0]
        self.SHRINKAGE = parametersGiven[1]

        print("parameters given: " + str(parametersGiven))

        #resetting parameters for correct displaying
        self.parameters = [
            self.LEARNING_RATE, self.SHRINKAGE, self.BASIS_FUNCTION.__name__,
            self.SIGMOID.__name__
        ]

        self.maxWeights = []
        for i in range(len(classes)):
            dummyWeight = np.zeros(17)
            self.maxWeights.append(dummyWeight)

        self.defaultWeights = []
        for i in range(len(self.CLASSES)):
            dummyWeight = np.zeros(17)
            self.defaultWeights.append(dummyWeight)
Esempio n. 10
0
def main(args=None):
    parser = argparse.ArgumentParser(description='Integral Flux Bin facility')

    parser.add_argument("-i", "--input", type=str,
                        dest='input', help='Input condor jobs WD')
    parser.add_argument("-o", "--output", type=str,
                            dest='output', help='output ROOT file')
    parser.add_argument("-f", "--filter", type=str,
                            dest='filter', help='File name to add')
    parser.add_argument("-b", "--bin_order", dest='bin_order', default=False,
                            action='store_true', help='integral for aladin facility')
    parser.add_argument("-n", "--number", type=int, dest='number',
                            const=10, nargs='?', help='Number of files to add')
    parser.add_argument("-v", "--verbose", dest='verbose', default=False,
                        action='store_true', help='run in high verbosity mode')

    opts = parser.parse_args(args)
    integral_helper = helper.helper()

    pars = {
        "input": opts.input,
        "output": opts.output,
        "filter": opts.filter,
        "bin_order": opts.bin_order,
        "number": opts.number,
        "verbose": opts.verbose
    }

    integral_helper.integral_flux_profile(pars)
Esempio n. 11
0
File: core.py Progetto: gkcn1990/LRS
	def __init__(self):
		self.playList = list()  # line:roleClass
		self.speakNow = 0
		self.speakRoundStart=-1
		self.dayState = day.night
		self.days = 0
		self.history = list()
		self.helper = helper.helper()
Esempio n. 12
0
def main(args=None):
    parser = ArgumentParser(description='DAMPE all-electron kompressor facility')
    parser.add_argument("-l", "--list", type=str,
                        dest='list', help='Input DATA/MC list')
    parser.add_argument("-c", "--config", type=str,
                        dest='config', help='Collector Config Directory')
    parser.add_argument("-o", "--output", type=str,
                        dest='output', help='HTC output directory')
    parser.add_argument("-m", "--mc", dest='mc',
                        default=False, action='store_true', help='MC event collector')
    parser.add_argument("-b", "--behaviour", type=str,
                            dest='behaviour', help='Variables regularizer facility')
    parser.add_argument("-f", "--file", type=int, dest='file',
                        const=100, nargs='?', help='files to process in job')
    parser.add_argument("-x", "--executable", type=str,
                        dest='executable', help='Analysis script')
    parser.add_argument("-v", "--verbose", dest='verbose', default=False,
                        action='store_true', help='run in high verbosity mode')
    parser.add_argument("-r", "--recreate", dest='recreate', default=False,
                        action='store_true', help='recreate output dirs if present')
    parser.add_argument("-a", "--append", dest='append', default=False,
                        action='store_true', help='append jobs folder to existing directory')
    
    opts = parser.parse_args(args)
    collector_helper = helper.helper()
    
    pars = {
        "list": opts.list,
        "config": opts.config,
        "output": opts.output,
        "mc": opts.mc,
        "regularize": opts.behaviour,
        "files": opts.file,
        "executable": opts.executable,
        "verbose": opts.verbose,
        "recreate": opts.recreate
    }

    task = {
        "collector": False, 
        "kompressor": True, 
        "aladin": False, 
        "split": False, 
        "acceptance": False, 
        "efficiency": False,
        "signal_selection": False,
        "xtrl": False,
        "selection_split": False,
        "bdt_electron_selection": False,
        "flux_bin_profile": False,
        "preselection": False
    }

    start_idx = get_folder_index(opts.output) if opts.append else 0
        
    collector_helper.parse_input_list(pars, start_idx)
    collector_helper.create_condor_files(pars, task)
    collector_helper.submit_jobs()
Esempio n. 13
0
File: core.py Progetto: gkcn1990/LRS
	def __init__(self, flow):
		self.playersInfo = list()  # init befor start;line:uid,nickname
		self.playersInfoWithIdentity = list()  # line:id,uid,nickname,Identity
		self.helper = helper.helper()
		self.flow = self.helper.getHelper("flow",flow)
		self.interface=self.helper.getHelper("interface",self.flow.interface)

		self._stop = False
		self.lazyInit()
 def downLoad_click(self,row,column):
     songTitle =self.table.item(row, 0).text()
     singer = self.table.item(row, 1).text()
     songUrl = self.table.item(row, 2).text()
     helperModel = helper(None)
     
     #QtGui.QMessageBox.information(None, u"tips",u"%s,%s,%s" % (songTitle,singer,songUrl))
     self.curDownloadRowNum = row
     localPath ="%s%s%s" % (self.stroagePath+"/",_fromUtf8((str(songTitle)).strip()),".mp3")
     urllib.urlretrieve(str(songUrl), localPath, self.downloadCallback)
Esempio n. 15
0
    def downLoad_click(self, row, column):
        songTitle = self.table.item(row, 0).text()
        singer = self.table.item(row, 1).text()
        songUrl = self.table.item(row, 2).text()
        helperModel = helper(None)

        #QtGui.QMessageBox.information(None, u"tips",u"%s,%s,%s" % (songTitle,singer,songUrl))
        self.curDownloadRowNum = row
        localPath = "%s%s%s" % (self.stroagePath + "/",
                                _fromUtf8((str(songTitle)).strip()), ".mp3")
        urllib.urlretrieve(str(songUrl), localPath, self.downloadCallback)
Esempio n. 16
0
def main(argv):
    if (len(sys.argv) != 8):
        helper.helper()
        sys.exit(84)
    checker()

    flag = int(sys.argv[1])
    a0 = int(sys.argv[2])
    a1 = int(sys.argv[3])
    a2 = int(sys.argv[4])
    a3 = int(sys.argv[5])
    a4 = int(sys.argv[6])
    prec = int(sys.argv[7])
    equa = [a0, a1, a2, a3, a4]
    if (flag == 1):
        bisection.bisection(equa, prec)
    elif (flag == 2):
        newton.newton(equa, prec)
    elif (flag == 3):
        secant.secant(equa, prec)
    exit(0)
Esempio n. 17
0
def main(args=None):
    parser = argparse.ArgumentParser(description='Aladin Split facility')

    parser.add_argument("-l", "--list", type=str,
                        dest='list', help='Input gaussianized DATA/MC list')
    parser.add_argument("-c", "--config", type=str,
                            dest='config', help='Collector Config Directory')
    parser.add_argument("-o", "--output", type=str,
                            dest='output', help='output ROOT file')
    parser.add_argument("-m", "--mc", dest='mc',
                            default=False, action='store_true', help='MC event collector')
    parser.add_argument("-f", "--file", type=int, dest='file',
                            const=10, nargs='?', help='files to process in job')
    parser.add_argument("-x", "--executable", type=str,
                        dest='executable', help='Analysis script')
    parser.add_argument("-v", "--verbose", dest='verbose', default=False,
                        action='store_true', help='run in high verbosity mode')
    parser.add_argument("-r", "--recreate", dest='recreate', default=False,
                        action='store_true', help='recreate output dirs if present')

    opts = parser.parse_args(args)
    aladinsplit_helper = helper.helper()

    pars = {
        "list": opts.list,
        "output": opts.output,
        "config": opts.config,
        "mc": opts.mc,
        "files": opts.file,
        "executable": opts.executable,
        "verbose": opts.verbose,
        "recreate": opts.recreate
    }

    task = {
        "collector": False, 
        "kompressor": False, 
        "aladin": False, 
        "split": True, 
        "acceptance": False, 
        "efficiency": False,
        "signal_selection": False,
        "xtrl": False,
        "selection_split": False,
        "bdt_electron_selection": False,
        "flux_bin_profile": False,
        "preselection": False
    }

    aladinsplit_helper.parse_input_list(pars, start_idx=0)
    aladinsplit_helper.create_condor_files(pars, task)
    aladinsplit_helper.submit_jobs()
Esempio n. 18
0
def main(args=None):
    parser = argparse.ArgumentParser(description='Status check facility')

    parser.add_argument("-i",
                        "--input",
                        type=str,
                        dest='input',
                        help='Input DATA/MC folder')
    parser.add_argument("-r",
                        "--resubmit",
                        dest='resubmit',
                        default=False,
                        action='store_true',
                        help='HTCondor flag to resubmit failed jobs')
    parser.add_argument("-l",
                        "--list",
                        dest='list',
                        default=False,
                        action='store_true',
                        help='Produce file list')
    parser.add_argument("-s",
                        "--split",
                        dest='split',
                        default=False,
                        action='store_true',
                        help='Split file list by energy bin')
    parser.add_argument("-m",
                        "--modify_sub_file",
                        type=str,
                        dest='modify_sub_file',
                        default="cndr.sub",
                        help='HTCondor sub file name')
    parser.add_argument("-v",
                        "--verbose",
                        dest='verbose',
                        default=False,
                        action='store_true',
                        help='run in high verbosity mode')

    opts = parser.parse_args(args)
    status_helper = helper.helper()

    pars = {
        "input": opts.input,
        "resubmit": opts.resubmit,
        "list": opts.list,
        "split": opts.split,
        "modify_sub_file": opts.modify_sub_file,
        "verbose": opts.verbose
    }

    status_helper.status(pars)
Esempio n. 19
0
    def __init__(self, request=None):

        self.ip = None
        self.user_agent = None
        self.session_id = None
        self.method = None
        self.base_url = None
        self.endpoint = None
        self.full_path = None

        if request:
            self.ip = request.remote_addr
            self.user_agent = request.user_agent
            self.session_id = request.cookies.get('sessionId', None)
            self.method = request.method
            self.base_url = request.base_url
            self.endpoint = request.endpoint
            self.full_path = request.full_path

        # set session_id if blank
        if not self.session_id:
            self.session_id = helper().get_uuid()

        # Log request
        record_type = 'kraken:log'
        record_id = None
        data = {
            'kraken:date': helper().datetime_now(),
            'kraken:ip': self.ip,
            'kraken:method': self.method,
            'kraken:base_url': self.base_url,
            'kraken:endpoint': self.endpoint,
            'kraken:full_path': self.full_path,
            'kraken:session_id': self.session_id
        }
        record = {}
        record['data'] = data
        kraken_post_record(record_type, record_id, record)
        post_bigquery_log(helper().datetime_now(), self.ip, self.full_path)
def checkfirstargument():

    # function to check user supplied argument to determine functionality of the app

    try:  # if your looking for the client portion
        if str(sa1).lower() in ["client", "c"]:
            from client_kicker import initclient
            from scanconfig import initscanner
            from diagforall import checkdepends
            from diagforall import diagclientheader
            try:
                checkdepends().required_mods(
                )  # check dependencies before launch
            except Exception as requiredmodsfail:
                print bo + "\n\n\t[?] Please ensure all dependencies are installed\n" + be
                helper().chelp()
                sys.exit(0)
            try:
                diagclientheader().clientheader()
                initclient().clientrun()  # run client kicker
            except Exception as clientrunfail:
                print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
                helper().chelp()
                sys.exit(0)
            try:
                initscanner().scanengine()  # configure and run scanning engine
            except Exception as scanenginefail:
                print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
                helper().chelp()
                sys.exit(0)
        if str(sa1).lower() in ["server",
                                "s"]:  # if your looking for the server portion
            __builtin__.diag = "yes"  # since server does not get settings from ini file
            try:
                from servargs import args
                args().getservargs()
                try:
                    from server_kicker import initserver
                    initserver().serverrun()
                except Exception as serverrunfail:
                    print bo + "\n\n\t[?] Please ensure all variables are given\n" + be
                pass
            except Exception as serverinitfail:
                print bo + "\n\n\t[?] Failed server initialization" + str(
                    serverinitfail)
    except Exception as nofirstargument:
        print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
        helper().helpall()
        sys.exit(0)
 def downLoad_click_thread(self,row,column):
     songTitle =self.table.item(row, 0).text()
     singer = self.table.item(row, 1).text()
     songUrl = self.table.item(row, 2).text()
     helperModel = helper(None)
     
     self.curDownloadRowNum = row
     localPath ="%s%s%s" % (self.stroagePath+"/",_fromUtf8((str(songTitle)).strip()),".mp3")
 
     #urllib.urlretrieve(str(songUrl), localPath, self.downloadCallback)
     self.lock = RLock()
     thread = Thread(target=self.download(songUrl,localPath))
     thread.setDaemon(True)
     thread.start()
Esempio n. 22
0
def checkfirstargument():


	# function to check user supplied argument to determine functionality of the app

	try:  # if your looking for the client portion
		if str(sa1).lower() in ["client", "c"]:
			from client_kicker import initclient
			from scanconfig import initscanner
			from diagforall import checkdepends
			from diagforall import diagclientheader
			try:
				checkdepends().required_mods()  # check dependencies before launch
			except Exception as requiredmodsfail:
				print bo + "\n\n\t[?] Please ensure all dependencies are installed\n" + be
				helper().chelp()
				sys.exit(0)
			try:
				diagclientheader().clientheader()
				initclient().clientrun()  # run client kicker
			except Exception as clientrunfail:
				print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
				helper().chelp()
				sys.exit(0)
			try:
				initscanner().scanengine()  # configure and run scanning engine
			except Exception as scanenginefail:
				print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
				helper().chelp()
				sys.exit(0)
		if str(sa1).lower() in ["server", "s"]:  # if your looking for the server portion
			__builtin__.diag = "yes"  # since server does not get settings from ini file
			try:
				from servargs import args
				args().getservargs()
				try:
					from server_kicker import initserver
					initserver().serverrun()
				except Exception as serverrunfail:
					print bo + "\n\n\t[?] Please ensure all variables are given\n" + be
				pass
			except Exception as serverinitfail:
				print bo + "\n\n\t[?] Failed server initialization" + str(serverinitfail)
	except Exception as nofirstargument:
		print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
		helper().helpall()
		sys.exit(0)
Esempio n. 23
0
def svg2pickle(SVG_SRC, path_lst, out):
    """build svg database
  IN:  SVG_SRC  directory containing svg files
       path_lst file containing list of the svg images + labels
  OUT: out      output file (pickle)
  """
    helps = helper()
    lists = helps.read_list(path_lst, ',', keep_original=False)
    labels = lists[0]
    paths = lists[1]
    if paths[0].endswith('.png'):
        paths = [path.replace('.png', '.svg') for path in paths]

    data = [SVGProcessor(os.path.join(SVG_SRC, path)) for path in paths]
    helps.save(out, labels=labels, data=data)
Esempio n. 24
0
    def downLoad_click_thread(self, row, column):
        songTitle = self.table.item(row, 0).text()
        singer = self.table.item(row, 1).text()
        songUrl = self.table.item(row, 2).text()
        helperModel = helper(None)

        self.curDownloadRowNum = row
        localPath = "%s%s%s" % (self.stroagePath + "/",
                                _fromUtf8((str(songTitle)).strip()), ".mp3")

        #urllib.urlretrieve(str(songUrl), localPath, self.downloadCallback)
        self.lock = RLock()
        thread = Thread(target=self.download(songUrl, localPath))
        thread.setDaemon(True)
        thread.start()
Esempio n. 25
0
def main():

    sc = helper(url, path, style, True)
    sc.get_class_v1()  # Get class name from web (146 Class)
    sc.get_cssurl()  # Get css page from web
    data, result = sc.class_name, ""
    for i in range(len(data)):
        result = str(sc.get_attr(data[i]))  # Check found class and not found class

    # [Count] All Class in html - 243 | Found Class in css - 72 | Not Found in css - 117
    print(len(sc.class_name), len(sc.found_attr), len(sc.notfound_attr))
    # ============================================================================================================

    convert = cssjson()  # object variable
    class_found = sc.found_attr  # found class in html (found 126 class)
    print("[Process] - Convert css to dict")
    convert.visualizer(
        sc.allcss
    )  # นำข้อมูลไฟล์ css ทุกไฟล์มารวมกันแล้วเปลี่ยน type เป็น dict
    css_dict = convert.data  # dictionary all css
    print("[Process] - Find Path and tag class")
    datatest = {}
    for j in range(len(class_found)):
        datatag = ["html", "body", "body,html"]
        name = str(class_found[j])
        clname = sc.addon(name)  # [<div class="shopee-progress-bar"></div>, 'div']
        try:
            xpath = sc.xpath_soup(clname[0])  # ['html', 'body', 'div', 'div', 'div']
            for ex in range(len(xpath)):
                tag = clname[1]
                if tag not in datatag:
                    datatag.append(tag)

            clone = copy.deepcopy(css_dict["children"]["." + name]["attributes"])
            for xe in range(len(datatag)):
                try:  # วนใน tag ทั้งหมด หากไม่พบ tag ใดๆ ก็ให้วน tag อื่นต่อ เลยต้องใส่ try เพื่อไม่ให้หลุดออกจาก loop แล้วเก็บ atr tag อื่นๆต่อไป
                    merge = css_dict["children"][datatag[xe]]["attributes"]
                    css_dict["children"]["." + name]["attributes"].update(merge)
                except:
                    pass
                    # print(name, datatag[xe])
            css_dict["children"]["." + name]["attributes"].update(clone)
        except:
            pass

    final = open("final.json", "w+", encoding="utf-8")
    final.write(str(css_dict))
    final.close()
 def __init__(self, img_dir='', img_lst='', lmdb=''):
     self.have_img_lst = self.have_img_dir = self.have_lmdb = False
     self.hardsel = None
     if img_lst:
         helps = helper()
         self.img_lst = helps.read_list(img_lst,
                                        delimeter=',',
                                        keep_original=False)
         self.have_img_lst = True
     if img_dir:
         assert os.path.isdir(img_dir), 'Opps. img_dir is not a dir'
         self.img_dir = img_dir
         self.have_img_dir = True
     if lmdb:
         self.lmdb = lmdbs(lmdb)
         self.have_lmdb = True
Esempio n. 27
0
 def clientrun(self):
     # check for system argument to initialize client portion of application
     # log start time of application
     __builtin__.start_timer = time.time()
     try:
         is_host = re.match(
             "^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$",
             ipaddr)
         if is_host:
             __builtin__.host_ip = socket.gethostbyname(ipaddr)
         else:
             __builtin__.hostip == ipaddr
             pass
     except Exception as csetvarfail:
         print bo + "\n\n\t" + be + "[?] Could not set hostip address from ipaddress in conf.py" + str(
             csetvarfail)
     """ get system argument 2 which handles the configuration INI file"""
     try:
         __builtin__.conffile = sys.argv[2]
     except Exception as conffilefail:
         from helper import helper
         print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
         helper().chelp()
         sys.exit(0)
     """ get system argument 3, which handles SSL/TLS """
     try:
         if not sys.argv[3]:
             __builtin__.mytls = ""
         else:
             __builtin__.mytls = str(sys.argv[3])
     except Exception as nosysarg3:
         from helper import helper
         print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
         helper().chelp()
         sys.exit(0)
     """ set vars to user input provided from INI file from system argument 3 """
     try:
         if conffile:  # if var is set from system argument import confsecmap
             try:
                 from conf import confsecmap
             except Exception as confsecmapfail:
                 print(
                     "Failed at system argument configuration in main.py: "
                     + str(confsecmapfail))
             """ check and make sure its a file """
             if os.path.isfile(sys.argv[2]):
                 confsecmap
             clientconfdiag().diagconfig
     except Exception as conffilefail:
         from helper import helper
         print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
         helper().chelp()
         sys.exit(0)
Esempio n. 28
0
    def __init__(self, classes, maxSteps, maxNonChangingSteps, parameters):
        self.helper = helper()
        self.CLASSES = classes
        self.MAX_STEPS = maxSteps
        self.MAX_NONCHANGING_STEPS = maxNonChangingSteps

        self.LEARNING_RATE = parameters[0]
        self.SHRINKAGE = parameters[1]
        self.NUM_LAYERS = int(parameters[2])
        self.NEURONS_PER_LAYER = parameters[3] #NEURONSPERLAYER is a list of the number of neurons that exist per layer - excluding the bias neuron.
        random.seed()
        self.parameters = [self.LEARNING_RATE, self.SHRINKAGE, self.NUM_LAYERS, self.NEURONS_PER_LAYER, self.SIGMOID.__name__]

        self.maxWeights = []
        for k in range(len(self.NEURONS_PER_LAYER)-1):
            self.maxWeights.append(np.ones(shape=(self.NEURONS_PER_LAYER[k]+1, self.NEURONS_PER_LAYER[k+1])))
        for k in range(len(self.NEURONS_PER_LAYER)-1):
            for i in range(len(self.maxWeights[k])):
                for j in range(len(self.maxWeights[k][i])):
                    self.maxWeights[k][i][j] = random.uniform(-1, 1)/(self.NEURONS_PER_LAYER[k+1])**0.5
Esempio n. 29
0
    def __init__(self, classes, maxSteps, maxNonChangingSteps, parametersGiven):
        self.helper = helper()
        self.CLASSES = classes
        self.MAX_STEPS = maxSteps
        self.MAX_NONCHANGING_STEPS = maxNonChangingSteps
        self.LEARNING_RATE = parametersGiven[0]
        self.SHRINKAGE = parametersGiven[1]

        #resetting parameters for correct displaying
        self.parameters = [self.LEARNING_RATE, self.SHRINKAGE, self.BASIS_FUNCTION.__name__, self.SIGMOID.__name__]

        self.maxWeights = []
        for i in range(len(classes)):
            dummyWeight = np.zeros(17)
            self.maxWeights.append(dummyWeight)

        self.defaultWeights = []
        for i in range(len(self.CLASSES)):
            dummyWeight = np.zeros(17)
            self.defaultWeights.append(dummyWeight)
Esempio n. 30
0
def lmdb_get_info(DB):
    """
  get information about an lmdb
  IN:   DB    can be either a true lmdb or a python pickle
  includes: number of classes, number of sample per class, number of samples
  """
    if DB.endswith('.pkl'):
        helps = helper()
        data = helps.load(DB, 1)  #load the first variable which is the labels
        labels = data['labels']
    else:
        lmdb_ = lmdbs(DB)
        labels = lmdb_.get_label_list()
    out = {}
    out['num_classes'] = len(set(labels))
    out['num_samples'] = len(labels)
    if out['num_samples'] % out['num_classes'] != 0:
        print 'We got an unbalance lmdb having {} samples of {} classes'.format(\
          out['num_samples'],out['num_classes'])
    out['samples_per_class'] = out['num_samples'] / out['num_classes']
    return out
Esempio n. 31
0
    def __init__(self, classes, maxSteps, maxNonChangingSteps, parameters):
        self.helper = helper()
        self.CLASSES = classes
        self.MAX_STEPS = maxSteps
        self.MAX_NONCHANGING_STEPS = maxNonChangingSteps
        self.LEARNING_RATE = parameters[0]
        self.SHRINKAGE = parameters[1]
        self.BETA = parameters[2]
        self.REGULARIZER = parameters[3]

        self.parameters = [self.LEARNING_RATE, self.SHRINKAGE, self.BETA, self.REGULARIZER, self.BASIS_FUNCTION.__name__, self.SIGMOID.__name__]

        self.maxWeights = []
        for i in range(len(classes)):
            dummyWeight = np.zeros(17)
            self.maxWeights.append(dummyWeight)

        self.defaultWeights = []
        for i in range(len(self.CLASSES)):
            dummyWeight = np.zeros(17)
            self.defaultWeights.append(dummyWeight)
Esempio n. 32
0
    def __init__(self, classes, maxSteps, maxNonChangingSteps, parameters):
        self.helper = helper()
        self.CLASSES = classes
        self.MAX_STEPS = maxSteps
        self.MAX_NONCHANGING_STEPS = maxNonChangingSteps

        self.LEARNING_RATE = parameters[0]
        self.SHRINKAGE = parameters[1]
        self.NUM_LAYERS = int(parameters[2])
        self.NEURONS_PER_LAYER = parameters[3] #NEURONSPERLAYER is a list of the number of neurons that exist per layer - excluding the bias neuron.
        self.batchSize = parameters[4]
        self.MOMENTUM = parameters[5]
        random.seed()
        self.parameters = [self.LEARNING_RATE, self.SHRINKAGE, self.NUM_LAYERS, self.NEURONS_PER_LAYER, self.SIGMOID.__name__, self.batchSize, self.MOMENTUM]

        self.maxWeights = []
        for k in range(len(self.NEURONS_PER_LAYER)-1):
            self.maxWeights.append(np.ones(shape=(self.NEURONS_PER_LAYER[k]+1, self.NEURONS_PER_LAYER[k+1])))
        for k in range(len(self.NEURONS_PER_LAYER)-1):
            for i in range(len(self.maxWeights[k])):
                for j in range(len(self.maxWeights[k][i])):
                    #Starting weights are set randomly, dependant on the number of inputs. Compare lecture 17, neuralnetworks slide 10.
                    self.maxWeights[k][i][j] = random.uniform(-1, 1)/(self.NEURONS_PER_LAYER[k+1])**0.5
 def LoginBaidu(self):
     if str(self.text_loginname.text()).strip()!='' and self.text_password.text()!='':          
         self.btnOk.setText(u'请耐心等待...')
         helperModel = helper(None)
         if not helperModel.recordsExistAndLasted():
             
             try:
                 if self.Login("http://wwww.baidu.com"):
                     self.close()
                     loaderWindow = Ui_MainWindow(str(self.text_loginname.text()).strip(),str(self.text_password.text()),parent=None)
                     loaderWindow.exec_()
                     
                 else:
                     QMessageBox.warning(self,u'登录失败',u'可能是用户名或密码有问题',QMessageBox.Yes)
                     self.btnOk.setText(u"再次登录")
             except:
                 raise
                 self.btnOk.setText(u"再次登录")
                 return
         else:
             self.close()
             loaderWindow = Ui_MainWindow(str(self.text_loginname.text()).strip(),str(self.text_password.text()),parent=None)
             loaderWindow.exec_()
Esempio n. 34
0
    def __init__(self, classes, maxSteps, maxNonChangingSteps, parameters):
        self.helper = helper()
        self.CLASSES = classes
        self.MAX_STEPS = maxSteps
        self.MAX_NONCHANGING_STEPS = maxNonChangingSteps
        self.LEARNING_RATE = parameters[0]
        self.SHRINKAGE = parameters[1]
        self.BETA = parameters[2]
        self.REGULARIZER = parameters[3]

        self.parameters = [
            self.LEARNING_RATE, self.SHRINKAGE, self.BETA, self.REGULARIZER,
            self.BASIS_FUNCTION.__name__, self.SIGMOID.__name__
        ]

        self.maxWeights = []
        for i in range(len(classes)):
            dummyWeight = np.zeros(17)
            self.maxWeights.append(dummyWeight)

        self.defaultWeights = []
        for i in range(len(self.CLASSES)):
            dummyWeight = np.zeros(17)
            self.defaultWeights.append(dummyWeight)
    def createDataWidget(self):
        helperModel = helper(None)
        
        if not helperModel.recordsExistAndLasted():
            helperModel.Login("http://www.baidu.com",self.username,self.password)
            
            
        #self.buildMusicList()
        musiczipfile = codecs.open(helperModel.currentPath+"/musicFile.txt")
        singerfile = codecs.open(helperModel.currentPath+"/singer.txt")
        songfile=codecs.open(helperModel.currentPath+"/song.txt")
        musiczipfilelines = musiczipfile.readlines()
        rowcount = len(musiczipfilelines)
        
        table = QTableWidget(rowcount,6)
        table.setEditTriggers(
            QtGui.QAbstractItemView.DoubleClicked |
            QtGui.QAbstractItemView.SelectedClicked)
        table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
        table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        table.setHorizontalHeaderLabels([u"歌名",u"歌手",u'url',u"", u'',''])
       
        rowNumber = 0
        for song,singer,url in zip(songfile.readlines(),singerfile.readlines(),musiczipfilelines):
            item1 = QTableWidgetItem(helperModel.translate(song))
            item2 = QTableWidgetItem(helperModel.translate(singer))
            item3 = QTableWidgetItem(helperModel.translate(url))
            item4 = QTableWidgetItem()
            item4.setCheckState(0) 
            
            #item4.setCheckable(True) 
            item5 = QTableWidgetItem()
            #item5.setData(0, [song,singer,url])
            
            item6Progress = QTableWidgetItem()
            

            #item5.setData(0,True)
            table.setItem(rowNumber,0,item1)
            table.setItem(rowNumber,1,item2)
            table.setItem(rowNumber,2,item3)
            table.setItem(rowNumber,3,item4)
            table.setItem(rowNumber,4,item5)
            table.setItem(rowNumber,5,item6Progress)
            
            btn = fzDownloadButton(parent=table,rowNum=rowNumber,columnNum=4)
            table.setCellWidget(rowNumber,4,btn)
            
            #下载进度条
            progressBar = QtGui.QProgressBar()
            progressBar.setVisible(False)
            progressBar.setMaximum(100)
            
            progressBar.setStyleSheet('''QProgressBar {border: 2px solid grey;border-radius: 5px;text-align: center;}
                                         QProgressBar::chunk {background-color: #05B8CC;width: 10px;margin:0.5px;}''')
            table.setCellWidget(rowNumber,5,progressBar)
            table.connect(btn,SIGNAL("downloadclick(int , int)"),self.downLoad_click_thread)
           
            rowNumber+=1
           
        
        table.resizeColumnsToContents()
        table.setColumnHidden(2,True)
        table.setGeometry(80, 20, 400, 300)
        musiczipfile.close()
        singerfile.close()
        songfile.close()
        table.setObjectName(_fromUtf8("tableView"))
        return table
 def threadLogin(self):
     helperModel = helper(None)
     if not helperModel.recordsExistAndLasted():
         helperModel.Login("http://www.baidu.com",str(self.text_loginname.text()).strip(),str(self.text_password.text()))
    def __init__(self,parent=None):
        super(login,self).__init__(parent)
        
        
        self.getDefaultStroagePath()
        self.resize(QSize(378,292))
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)
        
                
        self.label_title = QLabel(u"风筝百度音乐下载器")
        self.label_title.setFixedHeight(30)
        
        self.btn_close = QPushButton()
        self.btn_close.setStyleSheet("""QPushButton{background-image:url(./img/btn_close_normal.png);width:39px;height:18px;padding-top:0px;border:0px;} 
                                    QPushButton:hover{background-image:url(./img/btn_close_highlight.png);}
                                    QPushButton:pressed{background-image:url(./img/btn_close_down.png);}""")
        
        self.btn_min = QPushButton()
        self.btn_min.setStyleSheet("QPushButton{background-image:url(./img/btn_close_normal1.png);width:39px;height:18px;padding-top:0px;border:0px;}")
      
        
        self.layout_top = QHBoxLayout() #顶部栏
        self.layout_top.addWidget(self.label_title,1,Qt.AlignLeft)
        self.layout_top.addWidget(self.btn_min,0,Qt.AlignRight | Qt.AlignTop)
        self.layout_top.addWidget(self.btn_close,0,Qt.AlignRight | Qt.AlignTop)

        self.label_loginname = QLabel(u"登录名:")
        self.text_loginname = QLineEdit()
        self.text_loginname.setFixedSize(QSize(230,30))
        #self.text_loginname.setStyleSheet("QLabel{margin:0px 0px 0px 55px;}")
        
        self.layout_loginname = QHBoxLayout()
        self.layout_loginname.addStretch()
        self.layout_loginname.addWidget(self.label_loginname)

        self.layout_loginname.addWidget(self.text_loginname)
        self.layout_loginname.addStretch()
        
        
        self.label_password = QLabel(u" 密码:")
        self.text_password = QLineEdit()
        self.text_password.setEchoMode(QLineEdit.Password)
        
        self.text_password.setFixedSize(QSize(230,30))
        
        self.layout_password = QHBoxLayout()
        self.layout_password.addStretch()
        self.layout_password.addWidget(self.label_password)
        self.layout_password.addWidget(self.text_password)
        self.layout_password.addStretch()
        
        self.btnOk = QPushButton(u"登录")
        self.btnOk.setFixedSize(QSize(120,60))
        
        self.layout_button = QHBoxLayout()
        self.layout_button.addStretch(1)
        self.layout_button.addWidget(self.btnOk)
        self.layout_button.addStretch(1)
        
        
        
        self.layout_main = QVBoxLayout() #整个布局外框
        self.layout_main.addLayout(self.layout_top)
        self.layout_main.addStretch() #平均分配空间
        self.layout_main.addLayout(self.layout_loginname)
        self.layout_main.addStretch() #平均分配空间
        self.layout_main.addLayout(self.layout_password)
        self.layout_main.addStretch() #平均分配空间
        self.layout_main.addLayout(self.layout_button)
        self.layout_main.addStretch() #平均分配空间
        self.setLayout(self.layout_main)
        self.layout_main.setContentsMargins(0,0,0,0)
        self.layout_main.setSpacing(0)
        
        QObject.connect(self.btn_close, SIGNAL("clicked()"),self.LoginExit)
        self.btn_min.clicked.connect(self.mini_click)
        self.connect(self.btnOk, SIGNAL("clicked()"),self.LoginBaidu)
        
        helperModel = helper(None)
        if helperModel.recordsExistAndLasted():
            self.close()
            loaderWindow = Ui_MainWindow(str(self.text_loginname.text()).strip(),str(self.text_password.text()),parent=None)
            loaderWindow.exec_()
Esempio n. 38
0
 def __init__(self, CLASSES, maxSteps, maxNonChangingSteps, parameters):
     self.helper = helper()
     self.CLASSES = CLASSES
Esempio n. 39
0
__author__ = 'Ronnie'

from helper import helper

helper("help, tech support")
Esempio n. 40
0
 def threadLogin(self):
     helperModel = helper(None)
     if not helperModel.recordsExistAndLasted():
         helperModel.Login("http://www.baidu.com",
                           str(self.text_loginname.text()).strip(),
                           str(self.text_password.text()))
Esempio n. 41
0
""" set some color variable shortcuts """
__builtin__.bh = b.HEADER
__builtin__.bf = b.FAIL
__builtin__.be = b.ENDC
__builtin__.bw = b.WARNING
__builtin__.bo = b.OKBLUE

""" do some basic testing of the colorization module """
ctest().colortest()

"""check for user supplied argument in position 1, assume blank is assumption """
try:
	__builtin__.sa1 = str(sys.argv[1])
except Exception as nofirstargument:
	print bo + "\n\n\t[?] Please ensure all arguments are given\n" + be
	helper().helpall()
	sys.exit(0)



def checkfirstargument():


	# function to check user supplied argument to determine functionality of the app

	try:  # if your looking for the client portion
		if str(sa1).lower() in ["client", "c"]:
			from client_kicker import initclient
			from scanconfig import initscanner
			from diagforall import checkdepends
			from diagforall import diagclientheader
Esempio n. 42
0
    def __init__(self, parent=None):
        super(login, self).__init__(parent)

        self.getDefaultStroagePath()
        self.resize(QSize(378, 292))
        self.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog)

        self.label_title = QLabel(u"风筝百度音乐下载器")
        self.label_title.setFixedHeight(30)

        self.btn_close = QPushButton()
        self.btn_close.setStyleSheet(
            """QPushButton{background-image:url(./img/btn_close_normal.png);width:39px;height:18px;padding-top:0px;border:0px;} 
                                    QPushButton:hover{background-image:url(./img/btn_close_highlight.png);}
                                    QPushButton:pressed{background-image:url(./img/btn_close_down.png);}"""
        )

        self.btn_min = QPushButton()
        self.btn_min.setStyleSheet(
            "QPushButton{background-image:url(./img/btn_close_normal1.png);width:39px;height:18px;padding-top:0px;border:0px;}"
        )

        self.layout_top = QHBoxLayout()  #顶部栏
        self.layout_top.addWidget(self.label_title, 1, Qt.AlignLeft)
        self.layout_top.addWidget(self.btn_min, 0, Qt.AlignRight | Qt.AlignTop)
        self.layout_top.addWidget(self.btn_close, 0,
                                  Qt.AlignRight | Qt.AlignTop)

        self.label_loginname = QLabel(u"登录名:")
        self.text_loginname = QLineEdit()
        self.text_loginname.setFixedSize(QSize(230, 30))
        #self.text_loginname.setStyleSheet("QLabel{margin:0px 0px 0px 55px;}")

        self.layout_loginname = QHBoxLayout()
        self.layout_loginname.addStretch()
        self.layout_loginname.addWidget(self.label_loginname)

        self.layout_loginname.addWidget(self.text_loginname)
        self.layout_loginname.addStretch()

        self.label_password = QLabel(u" 密码:")
        self.text_password = QLineEdit()
        self.text_password.setEchoMode(QLineEdit.Password)

        self.text_password.setFixedSize(QSize(230, 30))

        self.layout_password = QHBoxLayout()
        self.layout_password.addStretch()
        self.layout_password.addWidget(self.label_password)
        self.layout_password.addWidget(self.text_password)
        self.layout_password.addStretch()

        self.btnOk = QPushButton(u"登录")
        self.btnOk.setFixedSize(QSize(120, 60))

        self.layout_button = QHBoxLayout()
        self.layout_button.addStretch(1)
        self.layout_button.addWidget(self.btnOk)
        self.layout_button.addStretch(1)

        self.layout_main = QVBoxLayout()  #整个布局外框
        self.layout_main.addLayout(self.layout_top)
        self.layout_main.addStretch()  #平均分配空间
        self.layout_main.addLayout(self.layout_loginname)
        self.layout_main.addStretch()  #平均分配空间
        self.layout_main.addLayout(self.layout_password)
        self.layout_main.addStretch()  #平均分配空间
        self.layout_main.addLayout(self.layout_button)
        self.layout_main.addStretch()  #平均分配空间
        self.setLayout(self.layout_main)
        self.layout_main.setContentsMargins(0, 0, 0, 0)
        self.layout_main.setSpacing(0)

        QObject.connect(self.btn_close, SIGNAL("clicked()"), self.LoginExit)
        self.btn_min.clicked.connect(self.mini_click)
        self.connect(self.btnOk, SIGNAL("clicked()"), self.LoginBaidu)

        helperModel = helper(None)
        if helperModel.recordsExistAndLasted():
            self.close()
            loaderWindow = Ui_MainWindow(str(
                self.text_loginname.text()).strip(),
                                         str(self.text_password.text()),
                                         parent=None)
            loaderWindow.exec_()
import helper as hp
import get_temporal as gt
import pandas as pd
import numpy as np
from sklearn.utils import resample
from sklearn import svm
import sklearn.metrics as sm
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn import tree

k = 5

##to get churn and nonchurn and make a dataframe
labels = hp.helper()
x, y = labels.get_user_id(k)
c_id = x
nc_id = y
print(len(c_id), len(nc_id))
c_label = [1 for i in c_id]
nc_label = [0 for i in nc_id]
c_df = pd.DataFrame({'OwnerUserId': c_id, 'label': c_label})
nc_df = pd.DataFrame({'OwnerUserId': nc_id, 'label': nc_label})
fin_ldf = c_df.append(nc_df, ignore_index=True)
print(fin_ldf.shape)

##Get our features
t_df = gt.get_temporal(k)
print(t_df.shape)
result_df = pd.merge(t_df, fin_ldf, on='OwnerUserId')
print(result_df.shape)
Esempio n. 44
0
CLASSIFIERS = {'MLE': mleonevsall, 'SOFTZEROONE': softzeroone, 'HINGE': hinge, 'NN': neuralnetwork}
STEPFUNCTIONS = {'logstep': optLogarithmic, 'logstepInverse': optLogarithmicInverse, 'plus': plus}

MAXSTEPS = 70
MAXNONCHANGINGSTEPS = 10
PARAMETERS = None
parName = ""
folds = 10
inverseOptimization = False

classifier = None

#create start weights or read them
startWeights = None
trainingSample = None
helperInstance = helper()
filename = "../data/dataset-complete_90PercentTrainingSet_mini10Percent_standardized.arff"

#read cmd line arguments
print("\n--------------------------")
print("About to checking arguments...")
print("--------------------------\n")
for i in range(len(sys.argv)):
    if sys.argv[i] == "-h" or sys.argv[i] == "--help":
        print("Here should be your help.")
        sys.exit()
    elif sys.argv[i] == "-c" or sys.argv[i] == "--classifier":
        classifier = CLASSIFIERS[sys.argv[i+1]]

    elif sys.argv[i] == "-p" or sys.argv[i] == "--parameters":
        print("received parameters - processing them...")
Esempio n. 45
0
 def __init__(self):
     self.helper = helper()
Esempio n. 46
0
    def createDataWidget(self):
        helperModel = helper(None)

        if not helperModel.recordsExistAndLasted():
            helperModel.Login("http://www.baidu.com", self.username,
                              self.password)

        #self.buildMusicList()
        musiczipfile = codecs.open(helperModel.currentPath + "/musicFile.txt")
        singerfile = codecs.open(helperModel.currentPath + "/singer.txt")
        songfile = codecs.open(helperModel.currentPath + "/song.txt")
        musiczipfilelines = musiczipfile.readlines()
        rowcount = len(musiczipfilelines)

        table = QTableWidget(rowcount, 6)
        table.setEditTriggers(QtGui.QAbstractItemView.DoubleClicked
                              | QtGui.QAbstractItemView.SelectedClicked)
        table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
        table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        table.setHorizontalHeaderLabels([u"歌名", u"歌手", u'url', u"", u'', ''])

        rowNumber = 0
        for song, singer, url in zip(songfile.readlines(),
                                     singerfile.readlines(),
                                     musiczipfilelines):
            item1 = QTableWidgetItem(helperModel.translate(song))
            item2 = QTableWidgetItem(helperModel.translate(singer))
            item3 = QTableWidgetItem(helperModel.translate(url))
            item4 = QTableWidgetItem()
            item4.setCheckState(0)

            #item4.setCheckable(True)
            item5 = QTableWidgetItem()
            #item5.setData(0, [song,singer,url])

            item6Progress = QTableWidgetItem()

            #item5.setData(0,True)
            table.setItem(rowNumber, 0, item1)
            table.setItem(rowNumber, 1, item2)
            table.setItem(rowNumber, 2, item3)
            table.setItem(rowNumber, 3, item4)
            table.setItem(rowNumber, 4, item5)
            table.setItem(rowNumber, 5, item6Progress)

            btn = fzDownloadButton(parent=table, rowNum=rowNumber, columnNum=4)
            table.setCellWidget(rowNumber, 4, btn)

            #下载进度条
            progressBar = QtGui.QProgressBar()
            progressBar.setVisible(False)
            progressBar.setMaximum(100)

            progressBar.setStyleSheet(
                '''QProgressBar {border: 2px solid grey;border-radius: 5px;text-align: center;}
                                         QProgressBar::chunk {background-color: #05B8CC;width: 10px;margin:0.5px;}'''
            )
            table.setCellWidget(rowNumber, 5, progressBar)
            table.connect(btn, SIGNAL("downloadclick(int , int)"),
                          self.downLoad_click_thread)

            rowNumber += 1

        table.resizeColumnsToContents()
        table.setColumnHidden(2, True)
        table.setGeometry(80, 20, 400, 300)
        musiczipfile.close()
        singerfile.close()
        songfile.close()
        table.setObjectName(_fromUtf8("tableView"))
        return table
class api():
    api_url = "https://api2.musical.ly/"
    global_veriable = {}
    active_user = {}
    helper = helper()

    def __init__(self):
        var = 1

    def login(self, username, password):
        username = self.helper.xor(str=username)
        if os.path.exists(username + '.json'):
            with open(username + '.json', encoding='utf-8') as json_file:
                load = json.load(json_file)
                if (load.get('data')['user_id']):
                    self.active_user = load
                    return load
        password = self.helper.xor(password)
        url = self.api_url + "passport/user/login/?" + self.helper.query(
            self.helper.default_veriable(self.global_veriable))

        posts = {
            'mix_mode': 1,
            'username': username,
            'password': password,
            'email': None,
            'mobile': None,
            'account': None,
            'captcha': None
        }
        login = self.helper.request_post(url, posts)

        try:
            headers = {}
            for c in login.cookies:
                headers[c.name] = c.value

        except KeyError:
            headers = None
        success = {}
        if (login.status_code != 200):
            return login.status_code
        else:
            data = login.json()
            if (data.get('data') and (data.get('error_code') == None)):
                success['data'] = self.helper.user_data_export(
                    data.get('data'))
                success['cookies'] = headers
                with open(username + '.json', 'w') as outfile:
                    json.dump(success, outfile)
                return success
            else:
                return login.json()

    def home_list(self, user_data={}):
        url = self.api_url + "aweme/v1/feed/?count=20&offset=0&max_cursor=0&type=0&is_cold_start=1&pull_type=1&" + self.helper.query(
            self.helper.default_veriable(self.global_veriable))
        if (user_data.__len__() > 0):
            data = self.helper.request_get(self,
                                           url,
                                           session=self.active_user['cookies'])
        else:
            data = self.helper.request_get(self, url)
        return data.json()

    def search_user(self, text='teamtolga'):
        url = self.api_url + "aweme/v1/discover/search/?cursor=0&keyword=" + text + "&count=10&type=1&hot_search=0&" + self.helper.query(
            self.helper.default_veriable(self.global_veriable))
        data = self.helper.request_get(self, url)
        return data.json()

    def like_post(self, aweme_id=1, type='1', session={}):
        url = self.api_url + "aweme/v1/commit/item/digg/?aweme_id=" + aweme_id + "&type=" + type + "&retry_type=no_retry&from=3&" + self.helper.query(
            self.helper.default_veriable(self.global_veriable))
        data = self.helper.request_get(self, url, session=session)
        return data.json()

    def view_post(self, aweme_id=1, session={}):
        data = self.helper.default_veriable()
        data['aweme_type'] = 0
        data['play_delta'] = 1
        data['item_id'] = aweme_id
        url = self.api_url + "aweme/v1/aweme/stats/?" + self.helper.query(
            self.helper.default_veriable(self.global_veriable))

        data = self.helper.request_post(url, posts=data, session=session)
        return data.json()

    def follow(self, user_id='6594722549190574086', type='1', session={}):
        url = self.api_url + "aweme/v1/commit/follow/user/?user_id=" + str(
            user_id) + "&type=" + str(
                type) + "&retry_type=no_retry&from=3&" + self.helper.query(
                    self.helper.default_veriable(self.global_veriable))
        data = self.helper.request_get(self, url, session=session)
        return data.json()

    def user_info(self, user_id='6594722549190574086', session={}):
        url = self.api_url + "aweme/v1/user/?user_id=" + str(
            user_id) + "&" + self.helper.query(
                self.helper.default_veriable(self.global_veriable))
        if (session.__len__() > 0):
            data = self.helper.request_get(self, url, session=session)
        else:
            data = self.helper.request_get(self, url)
        return data.json()

    def user_video_list(self, user_id='6594722549190574086', session={}):
        url = self.api_url + "aweme/v1/aweme/post/?user_id=" + str(
            user_id
        ) + "&max_cursor=0&type=0&count=20&pull_type=1&" + self.helper.query(
            self.helper.default_veriable(self.global_veriable))
        if (session.__len__() > 0):
            data = self.helper.request_get(self, url, session=session)
        else:
            data = self.helper.request_get(self, url)
        return data.json()

    def register(self, user={}, extra={}):
        data = self.helper.default_veriable()
        data['mix_mode'] = '1'
        data['email'] = self.helper.xor(user['email'])
        data['password'] = self.helper.xor(user['password'])
        data['code'] = None
        data['recaptcha_token'] = None

        url = self.api_url + "passport/email/register/v2/?" + self.helper.query(
            self.helper.default_veriable(self.global_veriable))
        data = self.helper.request_post(url, posts=data)
        headers = {}
        for c in data.cookies:
            headers[c.name] = c.value
        send_data = {}
        send_data['data'] = data.json().get('data')
        send_data['cookies'] = headers
        return send_data

    def register_device(self):
        '''
            No Complate
        :return:
        '''
        header = {}
        data = open('./content.data', 'rb').read()
        sio = BytesIO(data)
        print(sio.read())
        header['Content-Type'] = 'application/octet-stream;tt-data=a'
        url = "http://applog.musical.ly/service/2/device_register/"
        data = self.helper.request_post(url, posts=data, costum_headers=header)
        print(data.content)

    def follow_list(self,
                    user_id='6594722549190574086',
                    count=20,
                    max_time=None,
                    session={}):
        if (max_time == None):
            max_time = int(round(time.time() * 1000))
        url = self.api_url + "aweme/v1/user/follower/list/?user_id=" + str(
            user_id) + "&count=" + str(count) + "&max_time=" + str(
                max_time) + "&retry_type=no_retry&" + self.helper.query(
                    self.helper.default_veriable(self.global_veriable))
        data = self.helper.request_get(self, url, session=session)
        return data.json()

    def following_list(self,
                       user_id='6594722549190574086',
                       count=20,
                       max_time=None,
                       session={}):
        if (max_time == None):
            max_time = int(round(time.time() * 1000))
        url = self.api_url + "aweme/v1/user/following/list/?user_id=" + str(
            user_id) + "&count=" + str(count) + "&max_time=" + str(
                max_time) + "&retry_type=no_retry&" + self.helper.query(
                    self.helper.default_veriable(self.global_veriable))
        data = self.helper.request_get(self, url, session=session)
        return data.json()
Esempio n. 48
0
 def __init__(self):
     self.cmdparser = commandParser.commandParser()
     self.twapi = twitterApi.twitterApi()
     self.cfg = config.config()
     self.verbose = self.cfg.getVerbose()
     self.helper = helper.helper()