0

All,

This may be a pretty novice question but I am stuck on how to do this in Python. What I need to do is, set the to and from params when requesting data from Panaramio.

http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=100&minx=-180&miny=-90&maxx=180&maxy=90&size=medium&mapfilter=true

Panoramio only allows you to return 100 records at a time so I need to build out the url string to show the advancement of the sets of 100. eg. 101-200, 201-300, etc. Is there an example anywhere that will show me how to do this type of paging using Python?

Thanks, Adam

UPDATE: The following example seems to do what I want it to do. Now I have to figure out how to do the actual iteration from 101-200, 201-300, etc...From there I can take those values and build out my query string. Does this make sense?

def counter(low, high):
    current = low
    while current <= high:
        yield current
        current += 100

if __name__ == '__main__':

    for c in counter(100, 200):
        print c

UPDATE #2: I was making it harder than it should have been

def counter(low, high):
    while low <= high:
        yield low, high
        low += 100   
        high += 100  

for i in counter(1, 100):
        print i
aeupinhere
  • 2,883
  • 6
  • 31
  • 39
  • The URL is just a string, and normal string concatenation methods work. Therefore, I don't think I understand your question. – Luke Sneeringer May 18 '11 at 14:57
  • possible duplicate of [Add params to given URL in Python](http://stackoverflow.com/questions/2506379/add-params-to-given-url-in-python) – Ignacio Vazquez-Abrams May 18 '11 at 14:57
  • It looks like what I am seeking is called an iterator [Iterator Example](http://stackoverflow.com/questions/19151/build-a-basic-python-iterator). I have no problems at all building the query string but I need to increase the to and from sizes in increments of 100. That's what I was asking for because I wasn't sure how to do it using Python. – aeupinhere May 18 '11 at 15:33
  • For best results, show the output you get from python, and the output you want to get. – Winston Ewert May 18 '11 at 19:20

1 Answers1

0
for number in range(1, 301, 100):
    low = number
    high = low + 100
Winston Ewert
  • 44,070
  • 10
  • 68
  • 83
  • @AdamEstrada, I read your update wrong. I'm not clear on what your problem is now. Is something wrong with the counter function. (It does the same thing range(100, 201, 100) would do so its useless but I'm not sure what your actual problem is. – Winston Ewert May 18 '11 at 16:50
  • I am using Panoramios REST API and GOOG has made it so that only 100 records are returned at a time. They allow you to use the to and from params to define the data that is returned in 100 record increments. I am trying to figure out how to implement these increments to build out my query strings. eg. http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=100&minx=-180&miny=-90&maxx=180&maxy=90&size=medium&mapfilter=true then http://www.panoramio.com/map/get_panoramas.php?set=public&from=101&to=200&minx=-180&miny=-90&maxx=180&maxy=90&size=medium&mapfilter=true etc. – aeupinhere May 18 '11 at 16:55
  • @AdamEstrada, I know what you are trying to do, I don't understand where you are stuck. You've already got both pieces so I have no idea what your problem is. – Winston Ewert May 18 '11 at 17:18
  • I was making it harder than it should have been ;-) See my other update – aeupinhere May 18 '11 at 17:40