Esempio n. 1
0
def pfGroup_pfIndex_vf(request,pfGroup,pfIndex):
  pfGroupArray=stockUtil.evalTextArray(stockUtil.read_config("portfolio","pfGroupArray"))
  pfNameArray=[]
  #print("pfGroup:" + pfGroup) 
  #print("pfIndex:" + pfIndex) 
  pfIndexNo=int(pfIndex.replace("pf",""))
  currentPortfolio = Portfolio.select().where(Portfolio.group  == pfGroup, Portfolio.index == pfIndexNo).dicts().first()
  #print(currentPortfolio)
  if currentPortfolio != None:
    stockArray=stockUtil.evalTextArray(currentPortfolio["stock_array"]) #stock_array is converted form string type to array
    currentPortfolio["stock_array"]=stockArray 
  if currentPortfolio == None:
    createPortfolio(pfGroup, "1", [])
    return HttpResponseRedirect("/portfolio/" + pfGroup + "/pf0")
  qry = Portfolio.select().where(Portfolio.group  == pfGroup).order_by(Portfolio.index)
  for i in qry:
    pfNameArray.append({"group":i.group,"index":i.index,"name":i.name})
  #print(currentPortfolio)  
  #print(pfNameArray)  
  return render(request,"portfolio.html",{"pfGroupArray":pfGroupArray, "pfGroup": pfGroup, "pfIndex": pfIndex, "pfNameArray": pfNameArray, "currentPortfolio": currentPortfolio})
Esempio n. 2
0
def pfGroup_deletePortfolioList_vf(request,pfGroup):
  if request.method == "POST":
     body_unicode = request.body.decode('utf-8')
     delIdStr = json.loads(body_unicode)
     delIdArray=delIdStr.split(",")
     for Id in delIdArray:
       #print(Id)
       q=Portfolio.delete().where(Portfolio.id == Id)
       q.execute()
     qry = Portfolio.select().where(Portfolio.group  == pfGroup).order_by(Portfolio.index)
     qry.count
     for index, item in enumerate(qry):
       #print(item._data)
       q = Portfolio.update(index=index).where(Portfolio.id == item.id)
       q.execute()
  return HttpResponseRedirect("/portfolio/" + pfGroup + "/pf0")
Esempio n. 3
0
def downloadData(pfGroup):
  qry = Portfolio.select().where(Portfolio.group == pfGroup).order_by(Portfolio.index)
  for item in qry:
    stockArray = stockUtil.evalTextArray(item.stock_array)
    for stock in stockArray:
      for i in range(0,2):
        try:
          downloadDataHistory(stock["stockId"], stock["marketType"])
          #downloadDataFinancial(stock["stockId"], stock["marketType"])
        except Exception as e:
          print("Unexpected error:", sys.exc_info()[0]) #print error type
          print(str(e))#print error message         
          continue #skip "break" instruction
          #raise
        break  #let stock be donload only 1 time if no exception.
  pollMsgQueue.append("History data download complete.")
Esempio n. 4
0
def pfGroup_pfIndex_chart_vf(request,pfGroup,pfIndex): #href link. render a new page.
  portfolioCount = Portfolio.select().where(Portfolio.group==pfGroup).count()
  #print(request.GET)
  return render(request, "portfolioWatchList_chart.html", 
        { "stockObj":{"stockId":request.GET.get("stockId"), "marketType":request.GET.get("marketType"), "stockName":request.GET.get("stockName")},
                "index":request.GET.get("index"), "period":request.GET.get("period"), "portfolioCount":portfolioCount})