home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 31 / FreelogHS31.iso / ArgentCompta / Bankperfect / bp.exe / Scripts / UpdateStock / update_stock.py < prev   
Text File  |  2005-07-24  |  1KB  |  48 lines

  1. import BP
  2.  
  3. current_account = BP.AccountCurrent()
  4. dates = BP.OperationDate[current_account]
  5. modes = BP.OperationMode[current_account]
  6. infos = BP.OperationDetails[current_account]
  7. thirds = BP.Operationthirdparty[current_account]
  8. values = BP.OperationAmount[current_account]
  9.  
  10. symb1 = BP.AccountCurrency1[current_account]
  11. symb2 = BP.AccountCurrency2[current_account]
  12. symb1, rate1 = symb1.split("|")
  13. symb2, rate2 = symb2.split("|")
  14. rate1 = float(rate1.replace(",", "."))
  15. rate2 = float(rate2.replace(",", "."))
  16.  
  17. nb_lines = len(dates)
  18.  
  19. def extract_value(s, start_points, right_bound):
  20.   for point in start_points:
  21.     i = s.find(point)
  22.     if i == -1: return ""
  23.     s = s[i + len(point):]
  24.   i = s.find(right_bound)
  25.   if i == -1: return ""
  26.   return s[:i]
  27.  
  28. for i in range(nb_lines):
  29.   if modes[i] == "Titre":
  30.     isin = infos[i]
  31.     if isin != "":
  32.       s = BP.GetURL("http://fr.finance.yahoo.com/q?s=%s" %isin)
  33.       s = extract_value(s, ["yfnc_tabledata1", "<b>"], "</b>")
  34.       s = s.strip().replace(",", ".")
  35.       p = s.find(" ")
  36.       if p > -1: s = s[:p]
  37.       p = s.find("&")
  38.       if p > -1: s = s[:p]
  39.       try:
  40.         val0 = float(s)
  41.         if symb2 == "Ç" and symb1 != "Ç":
  42.           val0 = val0 * rate1 / rate2
  43.         qty = float(thirds[i].split(" ")[0].replace(",", "."))
  44.         val = val0 * qty
  45.         values[i] = val
  46.       except:
  47.         pass
  48. BP.AccountRefreshScreen()