88import configparser
99from time import sleep
1010
11- VERSION = "2 .0"
11+ VERSION = "3 .0"
1212STARTPAGE = 1
13- FIRSTKEY = "AAAAAAADNfs ="
14- delta = 100
13+ FIRSTKEY = "AAAAAAAPnos ="
14+ delta = 314
1515BASEDIR = os .path .join (os .path .expanduser ('~' ), '.meile-cache' )
1616CONFFILE = os .path .join (BASEDIR ,'config.ini' )
1717CONFIG = configparser .ConfigParser ()
1818
1919API = "https://api.sentinel.mathnodes.com/"
20- ENDPOINT = "sentinel/subscriptions?pagination.key=%s&pagination.limit=1000"
20+ ENDPOINT = "sentinel/subscription/v3/ subscriptions?pagination.key=%s&pagination.limit=1000"
2121
2222SUBTYPES = {'node' : '/sentinel.subscription.v2.NodeSubscription' , 'plan' : '/sentinel.subscription.v2.PlanSubscription' }
2323
@@ -55,7 +55,10 @@ def GetSubscriptionAndPopulateDB(db):
5555 page_range = list (range (STARTPAGE ,STARTPAGE + delta ))
5656 k = 0
5757 while k < len (page_range ):
58- APIURL = API + ENDPOINT % NEXTKEY [- 1 ]
58+ if k == 0 :
59+ APIURL = "https://api.sentinel.mathnodes.com/sentinel/subscription/v3/subscriptions?pagination.limit=1000"
60+ else :
61+ APIURL = API + ENDPOINT % NEXTKEY [- 1 ]
5962 print ("Getting page: %s" % page_range [k ])
6063 try :
6164 r = requests .get (APIURL , timeout = 60 )
@@ -68,52 +71,41 @@ def GetSubscriptionAndPopulateDB(db):
6871 if subJSON ['subscriptions' ]:
6972 for sub in subJSON ['subscriptions' ]:
7073 try :
71- subtype = sub ['@type' ]
72- ID = sub ['base' ]['id' ]
73- subscriber = sub ['base' ]['address' ]
74- inactive = sub ['base' ]['inactive_at' ]
75- sub_date = sub ['base' ]['status_at' ]
76-
77- for key ,value in SUBTYPES .items ():
78- if value in subtype :
79- subtype = key
80-
81- if subtype == "plan" :
82- plan_id = sub ['plan_id' ]
83- denom = sub ['denom' ]
84- else :
85- node = sub ['node_address' ]
86- gb = sub ['gigabytes' ]
87- hours = sub ['hours' ]
88- denom = sub ['deposit' ]['denom' ]
89- deposit = sub ['deposit' ]['amount' ]
90-
74+ #subtype = sub['@type']
75+ ID = int (sub ['id' ])
76+ subscriber = sub ['acc_address' ]
77+ plan_id = int (sub ['plan_id' ])
78+ denom = sub ['price' ]['denom' ]
79+ base_value = float (sub ['price' ]['base_value' ])
80+ quote_value = int (sub ['price' ]['quote_value' ])
81+ policy = sub ['renewal_price_policy' ]
82+ status = sub ['status' ]
83+ inactive = sub ['inactive_at' ]
84+ sub_date = sub ['start_at' ]
85+
9186 except Exception as e :
9287 print (str (e ))
9388 continue
9489
9590
9691
9792 #print("%s,%s,%s,%s,%s" % (ID,subscriber,node,price,sub_date))
98- if subtype == "node" :
99- iquery = '''
100- INSERT IGNORE INTO subscriptions (id,owner,node,deposit,denomination,sub_date, inactive_date,type,gigabytes,hours)
101- VALUES
102- (%d,"%s","%s",%d,"%s","%s","%s","%s",%.3f,%.3f)
103- ''' % (int (ID ),subscriber ,node ,int (deposit ),denom ,sub_date ,inactive ,subtype ,float (gb ),float (hours ))
104- else :
105- iquery = '''
106- INSERT IGNORE INTO subscriptions (id,owner,denomination,sub_date,inactive_date,type,plan_id)
107- VALUES
108- (%d,"%s","%s","%s","%s","%s",%d)
109- ''' % (int (ID ),subscriber ,denom ,sub_date ,inactive ,subtype ,int (plan_id ))
93+
94+ iquery = '''
95+ INSERT IGNORE INTO subscriptions (id,owner,deposit,denomination,sub_date, inactive_date,type,plan_id,policy,base_value)
96+ VALUES
97+ (%d,"%s",%d,"%s","%s","%s","plan",%d,"%s",%.18f)
98+ ''' % (ID ,subscriber ,quote_value ,denom ,sub_date ,inactive ,plan_id ,policy ,base_value )
99+
100+
110101 print (iquery )
111102 InsertIntoSubTable (iquery ,db )
112103 k += 1
113104 try :
114105 NEXTKEY .append (subJSON ['pagination' ]['next_key' ])
115106 if NEXTKEY [- 1 ] == "null" :
116107 WriteConfig (CONFIG , CONFFILE , NEXTKEY )
108+ break
117109
118110 except Exception as e :
119111 print (str (e ))
0 commit comments