Example #1
0
	def __init__(self, objectLogicPath, object):
		Live.__init__(self,objectLogicPath, object)
		Walker.__init__(self, objectLogicPath, object)
		logicFileName = object.GetLogicFileName()
		configFile=ini.IniFile(objectLogicPath)
		configFile.ReadString("npc", "group")
		self.SetHealth(configFile.ReadInt("npc", "health"))
		self._clock = sf.Clock()
		self._alarm = False
Example #2
0
def home_items(data):
    from live import Live
    from upcoming import Upcoming
    home = [
        {
            'mode': 'archive',
            'title': 'Archive',
            'plot': 'CS:GO match archive, complete with all CS:GO pro matches.'
        },
    ]
    for i in home:
        items.add_item(i)
    live = re.findall(
        '<div class="live-matches">(.*?)<div class="section-spacer">', data,
        re.DOTALL)
    if live:
        for l in re.findall('<div class="live-match">(.*?)</table>', live[0],
                            re.DOTALL):
            items.add_item(Live(html_unescape(l)).item)
    upcoming = re.findall(
        '<div class="upcoming-matches">(.*?)<div class="results">', data,
        re.DOTALL)
    if upcoming:
        for u in re.findall('(<a href=".*?)</table>', upcoming[0], re.DOTALL):
            items.add_item(Upcoming(html_unescape(u)).item)
    items.list_items()
Example #3
0
def main(num):
    if num == 1:
        s.run(start=False)
    else:
        live_id_list, live_desc = s.get_rooms()
        for index, desc in enumerate(live_desc):
            print "场次:%s  %s" % (index, desc.encode('utf-8'))
        match_id = None
        live_count = len(live_id_list)
        while match_id is None:
            try:
                match_id = int(raw_input('请选择正确的场次: '))
                assert (match_id < live_count)
            except:
                match_id = None

        l = Live(live_id_list[match_id])
        l.run()
Example #4
0
def main(argv):
    #Fetches input arguments from cmd
    #-p <Period>, -x <Exchange>, -s <State> (backtesting, live or lvie simulation)
    #-c <Currency>, -m <multiple currencies> (insert as a list)

    try:
        opts, args = getopt.getopt(argv, 'p:x:s:c:m:')  #feed in input from cmd
    except:
        sys.exit(2)
    for opt, arg in opts:
        if opt in ('-p'):
            if arg.lower() in ['5m', '15m', '30m', '1h', '1d']:
                period = arg
            else:
                print('invalid period')
                sys.exit(2)
        if opt in ('-x'):
            if arg.lower() in ['poloniex', 'snp500', 'ernie']:
                exchange = arg
            else:
                print('invalid exchange')
                sys.exit(2)
        if opt in ('-s'):
            if arg.lower() in ['live', 'backtest', 'livesimul']:
                state = arg
            else:
                print('invalid state')
                sys.exit(2)
        if opt in ('-c'):
            if exchange == 'poloniex' and arg in ['BTC/USDT', 'OMG/BTC']:
                currencey = arg
            elif exchange == 'snp500' and arg in ['GOOG']:
                currencey = arg
            elif exchange == 'ernie' and arg in ['ewa', 'ewc', 'ige']:
                currencey = arg
            else:
                print('invalid currency for this exchange')
                sys.exit(2)
            currencyAr = [currencey]

        if opt in ('-m'):  #multiple series
            currencies = arg.split(',')
            for currencey in currencies:
                if exchange == 'poloniex' and currencey in [
                        'BTC/USDT', 'OMG/BTC', 'ETH/USDT', 'XMR/USDT'
                ]:
                    pass
                elif exchange == 'snp500' and currencey in ['GOOG']:
                    pass
                elif exchange == 'ernie' and currencey in [
                        'ewa', 'ewc', 'ige'
                ]:
                    pass
                else:
                    print('invalid currency for this exchange')
                    sys.exit(2)
                    break
            currenceyAr = currencies
    for count, curr in enumerate(currenceyAr):
        if '/' in curr:
            currenceyAr[count] = curr.replace('/', '_')
    #Data Directory:
    directory = 'C:/Users/Billy/Documents/Code/MeanRevertingStrategy/Data/'

    #Backtesting
    if state.lower() == 'backtest':
        test_model = Backtest(exchange, currenceyAr, period, directory)
        test_model.test_stationarity()

    #Live - Simulated
    if state.lower() == 'pseudolive':

        #######
        lookback = 26
        eigenVector = [0.76975358, -0.87789041, 0.08870492]
        ######

        liveObj = Live(lookback, eigenVector, pseudoLive=True)
        data = fetch_data(currenceyAr, exchange, directory, period)

        for count, priceList in enumerate(data):
            liveObj.tick(priceList, count)
        print(liveObj.balance)
        returns = []
        returns.append(0)
        for x in liveObj.returnsCumSum:
            returns.append(returns[-1] + x)
        plt.plot(returns)
        plt.show()

    #Live
    if state.lower() == 'live' or state.lower() == 'livesimul':

        #This will fetch the parametes from a previous backtest, sorry for gross code
        save_dir, name = directory + 'backtestedParameters/', ''
        for curr in currenceyAr:
            print(name)
            name = name + curr
        [evec, lookback,
         date] = dePickler(save_dir + name + '_simple_linear_strategy.pickle')
        print('\n\nUse the Eigenvector: ', evec, '\nWith the lookback of: ',
              lookback, ' periods\nBacktested on the date: ', date,
              ' ?? yes <y>, no <n>: ')
        continueVar = input()

        #run the live module if the user confirms so
        if continueVar == 'y':
            print('starting\n\n')
            liveObj = Live(exchange, currenceyAr, period, directory, name,
                           evec, lookback,
                           state.lower() == 'livesimul')
            if state.lower() == 'livesimul':
                for count, priceList in enumerate(liveObj.data[:1440]):
                    print(count)
                    liveObj.tick(priceList, count)
                plt.plot(liveObj.pnl)
                plt.show()

            else:
                while True:
                    liveObj.fetchPrice()
                    liveObj.tick(priceList)
                    if period == '5m':
                        time.sleep(300)
                    elif period == '10m':
                        time.sleep(600)
                    elif period == '15m':
                        time.sleep(900)
                    elif period == '1h':
                        time.sleep(3600)
                    elif period == '1d':
                        time.sleep(86400)

        else:
            sys.exit(2)
Example #5
0
def live(data):
    videos = data.get('video', [])
    for i in videos:
        items.add(Live(i).item)
    items.list()
Example #6
0
    # check if it comes with parameters

    if len(sys.argv) > 2:

        if sys.argv[2] in PARAMS:
            # has a parameter
            func = PARAMS[sys.argv[2]]
            # run that param function
            func()
        else:
            print('qmlview error: Invalid Parameter')
            print_help()
            house_keeping(3)
    else:
        # it has no other parameter
        run()

else:
    print('Usage: qmlview file or ./qmlview file')
    house_keeping(2)

# if live parameter is used
if LIVE_SET:
    live_obj = Live(os.path.realpath(sys.argv[1]))
    engine.rootObjects()[0].setProperty('__qmlview__live_o_bject', live_obj)
    engine.rootObjects()[0].setProperty('filename', sys.argv[1])
else:
    pass

house_keeping(app.exec())
Example #7
0
    def start(self, agfid, device_name, temp_file_dir):

        params = {
            'segment_list_file_abs_path':
            temp_file_dir + str(datetime.datetime.now())[:10] + '.m3u8',
            'segment_afid_list_file_abs_path':
            temp_file_dir + str(datetime.datetime.now())[:10] + '_afid.m3u8',
            'segement_time':
            8,
            'device_mount_point':
            '/dev/' + device_name
        }
        self.ffmpeg = FFmpeg(self.get_live_command(params))

        live = None
        if agfid == "":
            res, err = self.afs.create_gfid()
            if err is not None:
                return err
        live = Live(res.agfid)

        err = self.ffmpeg.start()
        start = timer()
        now = datetime.datetime.now()
        live_time = now

        for line in self.ffmpeg.get_stdout():
            line = line.decode()
            if self.ffmpeg.is_fail_to_find_video_device(line):
                err = "cannot find video device " + params['device_mount_point']
                return err

            if self.ffmpeg.is_video_device_busy(line):
                err = "cannot connect to video device " + params[
                    'device_mount_point'] + " since it is busy"
                return err

            if self.ffmpeg.is_creating_segment_ts(line):
                if is_m3u8_file_exists(params):
                    m3u8 = M3U8(params['segment_list_file_abs_path'])
                    afid_m3u8 = None
                    if not is_afid_m3u8_file_exists(params):
                        contents = m3u8.get_contents(
                            m3u8.get_number_of_line() - 1)
                        afid_m3u8 = M3U8(
                            params['segment_afid_list_file_abs_path'])
                        afid_m3u8.create_from_contents(contents)
                        afid_m3u8.append_end("\n")
                        afid_m3u8.append_end(live.cts_afid)
                    else:
                        contents = m3u8.get_contents(
                            m3u8.get_number_of_line() - 1)
                        afid_m3u8 = M3U8(
                            params['segment_afid_list_file_abs_path'])
                        afid_m3u8.append_end("\n")
                        afid_m3u8.append_end(contents[-1])
                        afid_m3u8.append_end(live.cts_afid)
                    live.set_afid_m3u8(afid_m3u8)
                    live.set_m3u8(m3u8)

                    res, err = self.afs.upload(live.get_afid_m3u8().abs_path)
                    if err is not None:
                        return err
                    res, err = self.afs.set_gfid(live.get_agfid(), res.afid)
                    if err is not None:
                        return err

                live.num_of_ts = live.num_of_ts + 1
                live_time += datetime.timedelta(0, params['segement_time'])

            cmd_out = "live_start=" + now.strftime(
                "%Y-%m-%d %H:%M:%S"
            ) + ";lastest_up_cdn=" + datetime.datetime.now().strftime(
                "%Y-%m-%d %H:%M:%S") + ";num_of_ts=" + str(
                    live.num_of_ts) + ";live_time=" + live_time.strftime(
                        "%Y-%m-%d %H:%M:%S") + ";agfid=" + live.agfid + ";"
            print(cmd_out, flush=True)
            logging.info(cmd_out)
            live.cts_abs_path = self.ffmpeg.get_file_name_current_segemnt_ts(
                line)

            if self.ffmpeg.is_creating_segment_list(line):
                if live.cts_abs_path != None:
                    res = self.afs.upload(live.cts_abs_path)
                    if err is not None:
                        return err
                    live.cts_afid = res.afid
                    os.remove(live.cts_abs_path)
        return err
Example #8
0
	def __init__(self, objectLogicPath, object):
		Live.__init__(self, objectLogicPath, object)
Example #9
0
# -*- coding: utf-8 -*-
'''
抓取各直播平台的主播相关信息
auth: litchi
date : 2017.12
'''
import yaml
from live import Live

if __name__ == '__main__':
    f = open('config.yaml')
    config = yaml.load(f)

    #单线程
    for x in config:
        spiders = Live(x['name'], x['url'])
        spiders.go()

    # demo
    # spiders = Live('douyu','https://www.douyu.com/gapi/rkc/directory/0_0/',2)
    # spiders.go()