Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make rp and xrange dynamic?
    primarykey
    data
    text
    <p>Hey guys many thanks for taking the time to look at my problem, I have been working on this code for about 1 week (I am new to coding and to python 1 week also) Currently the loop only works if x in xrange(x) and 'rp' : 'x' is the correct number of rows available from this xml. The xml updates throughout the day, I was wondering if anyone can offer a solution to make x dynamic?</p> <pre><code>import mechanize import urllib import json import re from sched import scheduler from time import time, sleep from sched import scheduler from time import time, sleep s = scheduler(time, sleep) def run_periodically(start, end, interval, func): event_time = start while event_time &lt; end: s.enterabs(event_time, 0, func, ()) event_time += interval s.run() def getData(): post_url = "urlofinterest_xml" browser = mechanize.Browser() browser.set_handle_robots(False) browser.addheaders = [('User-agent', 'Firefox')] ######These are the parameters you've got from checking with the aforementioned tools parameters = {'page' : '1', 'rp' : '8', 'sortname' : 'roi', 'sortorder' : 'desc' } #####Encode the parameters data = urllib.urlencode(parameters) trans_array = browser.open(post_url,data).read().decode('UTF-8') xmlload1 = json.loads(trans_array) pattern1 = re.compile('&gt;&amp;nbsp;&amp;nbsp;(.*)&lt;') pattern2 = re.compile('/control/profile/view/(.*)\' title=') pattern3 = re.compile('&lt;span style=\'font-size:12px;\'&gt;(.*)&lt;\/span&gt;') pattern4 = re.compile('title=\'Naps posted: (.*) Winners:') pattern5 = re.compile('Winners: (.*)\'&gt;&lt;img src=') for i in xrange(8): user_delimiter = xmlload1['rows'][i]['cell']['username'] selection_delimiter = xmlload1['rows'][i]['cell']['race_horse'] username_delimiter_results = re.findall(pattern1, user_delimiter)[0] userid_delimiter_results = int(re.findall(pattern2, user_delimiter)[0]) user_selection = re.findall(pattern3, selection_delimiter)[0] user_numberofselections = float(re.findall(pattern4, user_delimiter)[0]) user_numberofwinners = float(re.findall(pattern5, user_delimiter)[0]) strikeratecalc1 = user_numberofwinners/user_numberofselections strikeratecalc2 = strikeratecalc1*100 print "user id = ",userid_delimiter_results print "username = ",username_delimiter_results print "user selection = ",user_selection print "best price available as decimal = ",xmlload1['rows'][i]['cell'] ['tws.best_price'] print "race time = ",xmlload1['rows'][i]['cell']['race_time'] print "race meeting = ",xmlload1['rows'][i]['cell']['race_meeting'] print "ROI = ",xmlload1['rows'][i]['cell']['roi'] print "number of selections = ",user_numberofselections print "number of winners = ",user_numberofwinners print "Strike rate = ",strikeratecalc2,"%" print "" getData() run_periodically(time()+5, time()+1000000, 15, getData) </code></pre> <p>Kind regards AEA</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload