示例#1
0
def downloadBorsa(date):
    outdir = '/home/wzhu/download_daily/borsa.bulletin/{:%Y}'.format(date)
    if not os.path.exists(outdir):
	os.makedirs(outdir)
    print date

    for sess in [1,2]:
	url= url_tmpl.format(date, date, date, sess)
	print url 

	test='''
	req2 = None
	try:
	    req2 = s.request('GET', url)  #, allow_redirects=True)
	except:
	    # if connection broken, wait and redo
	    print "error, try again in 5 mins"
	    pause(300)
	    s = requests.Session()
	    req2 = s.request('GET', url) 
'''
	req2 = s.request('GET', url) 
	res = req2.headers.get('content-type')
	if pd.isnull(res):
	    print "no data on {}".format(date)
	    pause() #5 sec
	    break
        else:
	    filepath = '{}/ehb{:%Y%m%d}{}.zip'.format(outdir, date, sess)
            with open(filepath, "wb") as f:
	        f.write(req2.content)
	    pause(10) #20 sec
示例#2
0
def getSoupFromWeb(categ):
    if categ in ETNET_TYPES:
        categStr = categ + '.php'
    else:
        categStr = 'business.php?business={}'.format(categ)
    url = 'http://www.etnet.com.hk/www/tc/stocks/sector_{}'.format(categStr)
    req = requests.get(url)
    common.pause(1)
    soup = bs.BeautifulSoup(req.content)
    return soup
示例#3
0
def downloadRLC():
    req3 = s.get(RLCurl)
    res = req3.headers.get('content-disposition')
    if pd.isnull(res):
        print "no data on {}".format(d)
    elif 'filename' in res:
        filepath = '{}/RLC-RegisteredLoanContract/rlc.{:%Y%m%d}.txt'.format(
            outdir, dd.today())
        with open(filepath, "wb") as f:
            f.write(req3.content)
    pause()
示例#4
0
def downloadBorsa(date):
    for key in payloadMap.keys():
        req2 = s.post(url, headers=headers, data=getLoad(payloadMap[key]))
        res = req2.headers.get('content-disposition')
        if pd.isnull(res):
            print "no data on {}".format(date)
        elif 'filename' in res:
            filename = res.split('=')[1]
            print filename
            filepath = '{}/{:%Y%m%d}.{}'.format(outdir, date, filename)
            with open(filepath, "wb") as f:
                f.write(req2.content)

# pause 5 secs
        pause()
示例#5
0
def downloadBTCDateRange(start, end):
    for d in pd.DateRange(start, end):
        addDateToPayload(d)
        req2 = s.post(BTCurl, headers=headers, data=payload)

        res = req2.headers.get('content-disposition')
        if pd.isnull(res):
            print "no data on {}".format(d)
        elif 'filename' in res:
            filename = res.split('=')[1]
            print filename
            filepath = '{}/BTC-OpenPositions/{}'.format(outdir, filename)
            with open(filepath, "wb") as f:
                f.write(req2.content)
        # pause 5 secs
        pause()
示例#6
0
def downloadBorsa(date):
    outdir = '/home/wzhu/download_daily/borsa.bulletin/{:%Y}'.format(date)
    if not os.path.exists(outdir):
	os.makedirs(outdir)
    print date

    for sess in [1,2]:
        req2 = s.post(url,headers=headers,data=getLoad(date,sess))
	pause() #5 sec
        res = req2.headers.get('content-disposition')
        if pd.isnull(res):
	    print "no data on {}".format(date)
	    break
        elif 'filename' in res:
	    filename = res.split('=')[1]
            print filename
	    filepath = '{}/{}'.format(outdir, filename)
            with open(filepath, "wb") as f:
	        f.write(req2.content)
示例#7
0
def create_dk_run_script(pname, write_to_file=False):
    """
    Takes in the name of a program and 
    convert its script file (pname.sh) 
    to Daikon run script (pname_dk.sh)


    EXAMPLES:
    ./inv cohendiv 5 2  
    => 
    kvasir-dtrace -q --dtrace-file=cohendiv/19.dtrace --program-stdout=cohendiv/1.out --program-stderr=cohendiv/1.err ./inv cohendiv 5 2 &> cohendiv/1.dk_err
    """

    script_file = pname + '.sh'

    assert os.path.isfile(script_file)

    lines = CM.vread(script_file, verbose=verbose).splitlines()
    lines = [cmd for cmd in lines if not cmd.startswith('#')]

    #disallow something like './inv cohendiv 5 2 #comment'
    assert all('#' not in cmd for cmd in lines)

    kvasir = "kvasir-dtrace -q " +\
        "--dtrace-file={pn}/{i}.dtrace --program-stdout={pn}/{i}.out " +\
        "--program-stderr={pn}/{i}.err {cmd} &> {pn}/{i}.dk_err"

    dk_lines = [
        kvasir.format(pn=pname, i=i, cmd=cmd) for i, cmd in enumerate(lines)
    ]

    dk_script = '\n'.join(dk_lines)

    if write_to_file:
        dk_script_file = '{}_dk.sh'.format(pname)
        if os.path.exists(dk_script_file):
            CM.pause(
                'Overwrite {} ? (Ctr + c to abort)'.format(dk_script_file))

        CM.vwrite(dk_script_file, dk_script)
    else:
        print dk_script
def create_dk_run_script(pname, write_to_file=False):
    """
    Takes in the name of a program and 
    convert its script file (pname.sh) 
    to Daikon run script (pname_dk.sh)


    EXAMPLES:
    ./inv cohendiv 5 2  
    => 
    kvasir-dtrace -q --dtrace-file=cohendiv/19.dtrace --program-stdout=cohendiv/1.out --program-stderr=cohendiv/1.err ./inv cohendiv 5 2 &> cohendiv/1.dk_err
    """

    script_file = pname + '.sh'

    assert os.path.isfile(script_file) 
        

    lines = CM.vread(script_file,verbose=verbose).splitlines()
    lines = [cmd for cmd in lines if not cmd.startswith('#')]

    #disallow something like './inv cohendiv 5 2 #comment'
    assert all('#' not in cmd for cmd in lines)  

    kvasir = "kvasir-dtrace -q " +\
        "--dtrace-file={pn}/{i}.dtrace --program-stdout={pn}/{i}.out " +\
        "--program-stderr={pn}/{i}.err {cmd} &> {pn}/{i}.dk_err"
        
    dk_lines = [kvasir.format(pn=pname,i=i,cmd=cmd)
                for i,cmd in enumerate(lines)]

    dk_script = '\n'.join(dk_lines)


    if write_to_file:
        dk_script_file = '{}_dk.sh'.format(pname)
        if os.path.exists(dk_script_file):
            CM.pause('Overwrite {} ? (Ctr + c to abort)'.format(dk_script_file))

        CM.vwrite(dk_script_file,dk_script)
    else:
        print dk_script
示例#9
0
from common import pause, problem

problem(1.1)
'''
    1. Create a Python script that has three variables: ip_addr1, ip_addr2, ip_addr3, all representing corresponding IP addresses. Print all of them to standard output using a singular print statement
    - Terminal output
    - Variable assignment
'''
ip_addr1 = "1.1.100.41"
ip_addr2 = "1.1.100.93"
ip_addr3 = "1.1.100.52"

print(ip_addr1, ip_addr2, ip_addr3)

pause()

problem(1.2)
'''
    2. Prompt a user to enter an IP address from the command line. Break the IP down into individual octets and print each octet as a decimal, binary and hexadecimal.
    - Taking user input
    - String manipulation
    - Type conversion
'''
ip = input("Please enter a valid IP Address:\n>>> ")

if ip == "":
    ip = '1'

octets = ip.split(".")
for i in octets:
    i = int(i)