示例#1
0
文件: parse.py 项目: numerals/forq
def main():
    """
    Requests a random quote using forismatic API
    """
    quote = gq.getQuote()
    text = quote.readJSON(sys.argv[1], sys.argv[2])
    print(text) # print the requested
示例#2
0
def main():
    """
    Requests a random quote using forismatic API
    """
    quote = gq.getQuote()
    text = quote.readJSON(sys.argv[1], sys.argv[2])
    print(text)  # print the requested
示例#3
0
def main():
    """
    Requests a random quote using forismatic API
    """
    quote = gq.getQuote()
    try:
        text = quote.requestQuote()  # get quote
        quote.parseJSON(text)  # check if parsable
        quote.saveJSON(text, sys.argv.pop())  # saving
    except:
        pass
示例#4
0
文件: generate.py 项目: numerals/forq
def main():
    """
    Requests a random quote using forismatic API
    """
    quote = gq.getQuote()
    try:
        text = quote.requestQuote() # get quote
        quote.parseJSON(text) # check if parsable
        quote.saveJSON(text, sys.argv.pop()) # saving
    except:
        pass
示例#5
0
securList =  ['AAPL', 'XLV', 'QQQ']
sharesList = {'AAPL':290, 'XLV':1400, 'QQQ':232}
quotes = getQuotes(securList)

#aapl = 96.25 02/22/16 290
#xlv = 71.41 04/27/16 1400
#qqq = 116.38 08/31/2016 232
from time import sleep
from os import system
from getQuote import getQuote

while True:
    allOutput = []
    header = 'Symbol\tTime\t\tPrice\tClose\t%Change\tDayGain'
    allOutput.append(header)
    totalGain = 0.0

    for i in securList:
        stock = getQuote(getQuotes(i), sharesList)
        totalGain += stock.gain

        output = '%s\t%s\t%s\t%s\t%s\t%s' % (stock.symbol, stock.time, stock.price, stock.prevClose, stock.dayChange, stock.gain)
        allOutput.append(output)

    sleep(1)
    system('clear')
    for i in allOutput:
        print i
    print 'Total Daily Gain: %f' % (totalGain)
示例#6
0
def Main(argv):
    flog.info("Start van programma.")
    global smtp_para

    # open van status database
    try:
        rt_status_db.init(const.FILE_DB_STATUS, const.DB_STATUS_TAB)
    except Exception as e:
        flog.critical(inspect.stack()[0][3] + ": Database niet te openen(1)." +
                      const.FILE_DB_STATUS + ") melding:" + str(e.args[0]))
        sys.exit(1)
    flog.debug(inspect.stack()[0][3] + ": database tabel " +
               const.DB_STATUS_TAB + " succesvol geopend.")

    # open van config database
    try:
        config_db.init(const.FILE_DB_CONFIG, const.DB_CONFIG_TAB)
    except Exception as e:
        flog.critical(inspect.stack()[0][3] + ": database niet te openen(2)." +
                      const.FILE_DB_CONFIG + ") melding:" + str(e.args[0]))
        sys.exit(1)
    flog.debug(inspect.stack()[0][3] + ": database tabel " +
               const.DB_CONFIG_TAB + " succesvol geopend.")

    # update field from database, the cli switches overwrite the DB values!

    _id, smtp_para['mailuser'], _label = config_db.strget(63, flog)
    _id, smtp_para['mailuserpassword'], _label = config_db.strget(64, flog)
    _id, smtp_para['mailserver'], _label = config_db.strget(65, flog)
    _id, smtp_para['mailserverport_ssl'], _label = config_db.strget(66, flog)
    _id, smtp_para['mailserverport_starttls'], _label = config_db.strget(
        67, flog)
    _id, smtp_para['mailserverport_plaintext'], _label = config_db.strget(
        68, flog)
    _id, smtp_para['subject'], _label = config_db.strget(69, flog)
    _id, to, _label = config_db.strget(70, flog)
    smtp_para['to'] = to.split()
    _id, cc, _label = config_db.strget(74, flog)
    smtp_para['cc'] = cc.split()
    _id, bcc, _label = config_db.strget(75, flog)
    smtp_para['bcc'] = bcc.split()
    _id, smtp_para['fromalias'], _label = config_db.strget(71, flog)
    _id, smtp_para['timeout'], _label = config_db.strget(72, flog)

    flog.debug(inspect.stack()[0][3] + ": parameters uit de DB:" +
               str(smtp_para))

    parser = argparse.ArgumentParser(description="smtp....")  # DB ID
    parser.add_argument('-u', '--mailuser', required=False)  #63
    parser.add_argument('-pw', '--mailuserpassword', required=False)  #64
    parser.add_argument('-srv', '--mailserver', required=False)  #65
    parser.add_argument('-pssl', '--mailserverport_ssl', required=False)  #66
    parser.add_argument('-pstls', '--mailserverport_starttls',
                        required=False)  #67
    parser.add_argument('-pplain',
                        '--mailserverport_plaintext',
                        required=False)  #68
    parser.add_argument('-subject', '--subject', required=False)  #69
    parser.add_argument('-to', '--to', action='append', required=False)  #70
    parser.add_argument('-cc', '--cc', action='append', required=False)  #74
    parser.add_argument('-bcc', '--bcc', action='append', required=False)  #75
    parser.add_argument('-from', '--fromalias', required=False)  #71
    parser.add_argument('-msgtext', '--messagetext', required=False)  #NONE
    parser.add_argument('-msghtml', '--messagehtml', required=False)  #NONE
    parser.add_argument('-time', '--timeout', required=False)  #72
    parser.add_argument('-a', '--attachment', action='append',
                        required=False)  #NONE
    parser.add_argument('-test',
                        '--testmail',
                        action='store_true',
                        required=False)  #NONE

    args = parser.parse_args()

    # send a test mail with default value
    if args.testmail != None:
        smtp_para['messagetext'] = "Dit is een test mail van de P1 monitor en mag genegeert worden. De mail is op " +  makeLocalTimeString() + " verzonden." + \
        "\n\n" + getQuote() + "\n\nBezoek https://www.ztatz.nl voor meer informatie over de P1 monitor."
        smtp_para[
            'subject'] = "P1 monitor test email van " + makeLocalTimeString(
            ) + "."

    if args.mailuser != None:
        smtp_para['mailuser'] = args.mailuser

    if args.mailuserpassword != None:
        smtp_para['mailuserpassword'] = args.mailuserpassword
    else:  #decode password
        try:
            smtp_para['mailuserpassword'] = base64.standard_b64decode(
                crypto3.p1Decrypt(smtp_para['mailuserpassword'],
                                  'mailpw')).decode('utf-8')
        except Exception as e:
            flog.error(inspect.stack()[0][3]+": password decodering gefaald. Decoded password="******" Gestopt. melding:" + str(e.args[0]) )
            sys.exit(16)
        flog.info("Password decryptie ok.")
        flog.debug("Decoded password = "******"P1 monitor version " + const.P1_VERSIE

    if args.messagehtml != None:
        smtp_para['messagehtml'] = args.messagehtml

    if args.messagetext != None:
        smtp_para['messagetext'] = args.messagetext

    if args.timeout != None:
        smtp_para['timeout'] = int(args.timeout)

    if args.attachment != None:
        #print ( args.attachment )
        for a in args.attachment:
            smtp_para['attachments'].append(a)

    flog.debug(inspect.stack()[0][3] + ": parameters na CLI parsing:" +
               str(smtp_para))

    #check if at least one reciever is given.
    cnt_valid_senders = 0
    for x in [smtp_para['to'], smtp_para['cc'], smtp_para['bcc']]:
        if len(x) > 0:
            cnt_valid_senders += 1

    if cnt_valid_senders == 0:
        flog.critical(inspect.stack()[0][3] +
                      ": geen TO,CC of BCC ontvangers opgegeven.")
        sys.exit(1)

    # 1 Start an SMTP connection that is secured from the beginning using SMTP_SSL().
    # 2 Start an unsecured SMTP connection that can then be encrypted using .starttls()
    # 3 Fallback to unsecure plaintext email.

    if sendSmtpMail('ssl') == False:
        flog.info(inspect.stack()[0][3] +
                  ": SSL/TSL verbinding is niet gelukt.")
        if sendSmtpMail('starttls') == False:
            flog.info(inspect.stack()[0][3] +
                      ": STARTTLS verbinding is niet gelukt.")
            if sendSmtpMail('plaintext') == False:
                flog.error("plaintext is mislukt gestopt.")
                sys.exit(1)

    #print ( sendSmtpMail('plaintext') )
    #print ( sendSmtpMail( 'starttls' ) )
    #print (  sendSmtpMail('ssl') )

    flog.info(inspect.stack()[0][3] + ": Programma is succesvol gestopt.")
    rt_status_db.timestamp(82, flog)
    sys.exit(0)  # all is well.