Пример #1
0
  def get(self):
    headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0'}
    session = requests.session()
    response = session.get('https://transferwise.com', headers=headers)
    response.raise_for_status()

    headers['X-Authorization-key'] = 'dad99d7d8e52c2c8aaf9fda788d8acdc'
    headers['X-Authorization-token'] = ''
    headers['X-Language'] = 'en'

    response = session.get('https://transferwise.com/api/v1/payment/calculate?amount=10000&amountCurrency=source&getNoticeMessages=true&hasDiscount=false&isFixedRate=false&isGuaranteedFixedTarget=false&payInMethod=ADYEN_DEBIT&sourceCurrency=EUR&targetCurrency=CHF', headers=headers)
    response.raise_for_status()
    transferwise = json.loads(response.content.decode('utf-8'))['transferwiseRate']/1.005

    response_currencyfair = session.get('https://app.currencyfair.com/calculator/quicktrade-quote?&mode=SELL&depositCurrency=EUR&beneficiaryCurrency=CHF&amount=10000')
    response_currencyfair.raise_for_status()
    currencyfair = json.loads(response_currencyfair.content.decode('utf-8'))['quote']['estimatesByTransferType']['1']['estimatedAmount']/10000

    response_xendpay = session.get('https://secure.xendpay.com/quote/api/get-quote?paymentCountryCode=DE&paymentCurrencyCode=EUR&deliveryCountryCode=CH&deliveryCurrencyCode=CHF&deliveryMethodCode=earthport-api&amount=10000.00&amountCurrencyCode=EUR&amountDeductFees=false&discretionalFee=&promoCode=')
    response_xendpay.raise_for_status()
    xendpay = float(json.loads(response_xendpay.content.decode('utf-8'))['data']['rate'])

    kvs = keyvalstore.KeyValueStore()
    timestamp = int(datetime.datetime.now().timestamp())
    for (value, key) in ((transferwise, "transferwise.history"), (currencyfair, "currencyfair.history"), (xendpay, "xendpay.history")):
      (history, ver) = kvs.get_versioned(key, [])
      history.append((timestamp, value))
      history = history[-100:]   # keep only up to 100 history values
      kvs.set_versioned(key, history, ver+1)

    return "{:.4f} - {:.4f} - {:.4f}".format(transferwise, currencyfair, xendpay)
Пример #2
0
 def update(socketio):
   newStatus = ""
   try:
     newStatus = Transferwise().get()
   except RequestException as e:
     print("RequestException while trying to fetch Transferwise. Exception: ", e)
     return (False, {})
   except Exception as e:
     print("Exception while trying to fetch Transferwise: ", e, traceback.print_tb(sys.exc_info()[2]))
     newStatus = Transferwise().get_buffered()
   if newStatus:
     keyvalstore.KeyValueStore().set("transferwise.rate", newStatus)
     print("{}: Updated Transferwise".format(datetime.datetime.now()))
   return (True, {'channel': 'transferwise', 'data': {'data': newStatus}})
Пример #3
0
 def update(socketio):
   newStatus = ""
   try:
     newStatus = Nettime().get()
   except RequestException as e:
     print("RequestException while trying to fetch Nettime. Exception: ", e)
     return (False, {})
   except Exception as e:
     print("Exception while trying to fetch Nettime: ", e)
     newStatus = Nettime().get_buffered()
   if newStatus:
     keyvalstore.KeyValueStore().set("nettime.status".format(zip), newStatus)
     print("{}: Updated Nettime".format(datetime.datetime.now()))
   return (True, {'channel': 'nettime', 'data': {'data': newStatus}})
Пример #4
0
 def update(socketio):
   ret = []
   for zip in ['895300', '804900']:
     newStatus = ""
     try:
       newStatus = MeteoSchweiz().get(zip)
     except RequestException as e:
       print("RequestException while trying to fetch MeteoSchweiz. Exception: ", e)
       return (False, {})
     except Exception as e:
       print("Exception while trying to fetch MeteoSchweiz: ", e)
       newStatus = MeteoSchweiz().get_buffered(zip)
     if (newStatus):
       keyvalstore.KeyValueStore().set("meteoschweiz.{}.fullJson".format(zip), newStatus)
       ret.append({'zip': zip, 'data': json.loads(newStatus)})
   print("{}: Updated MeteoSchweiz".format(datetime.datetime.now()))
   return (True, {'channel': 'weather', 'data': ret})
Пример #5
0
 def update(socketio):
   newStatus = []
   try:
     newStatus = dkb.get(3)
   except RequestException as e:
     print("RequestException while trying to fetch the finance status. Exception: ", e)
     return (False, {})
   except Exception as e:
     print("Exception while trying to fetch the finance status: ", e)
     newStatus = FinanceStatus().get_buffered() # set it to the old status so we do not retry in 30 seconds, the problem is probably sth completely different (e.g. parsing issues)
   oldStatus = FinanceStatus().get_buffered()
   if (newStatus): keyvalstore.KeyValueStore().set("financestatus.status3", newStatus)
   if newStatus and oldStatus != newStatus:
     print("{}: Finance status changed".format(datetime.datetime.now()))
     return (True, {'channel': 'message', 'data': "{}: Finance status changed".format(datetime.datetime.now())})
   print("{}: Updated finance status".format(datetime.datetime.now()))
   return (True, {})
Пример #6
0
 def get_buffered(self, zip='895300'):
   return keyvalstore.KeyValueStore().get("meteoschweiz.{}.fullJson".format(zip))
Пример #7
0
 def get_buffered(self):
   return keyvalstore.KeyValueStore().get("transferwise.rate")
Пример #8
0
def get_value():
    return str(keyvalstore.KeyValueStore().get(request.args['key']))
Пример #9
0
 def get_buffered(self):
   return keyvalstore.KeyValueStore().get("nettime.status")
Пример #10
0
 def get_buffered(self):
   return keyvalstore.KeyValueStore().get("financestatus.status3")