ddl

MyFunctions

ddl
Sep 2nd, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # Name:     download
  4. # Function: Copy the contents of a file from a given URL
  5. #       to a local file.
  6. # Parameter:    url - URL to the file, which should be donwloaded
  7. # Return:   none
  8. # Remarks:  none
  9.  
  10. import urllib
  11. def download(url):
  12.     webFile = urllib.urlopen(url)
  13.     localFile = open(url.split('/')[-1], 'w')
  14.     localFile.write(webFile.read())
  15.     webFile.close()
  16.     localFile.close()
  17.  
  18. # Name:     strstr
  19. # Function: Get string in string
  20. # Parameter:    sourcestring - String in which should be searched
  21. #       searchstring - String to search in sourcestring
  22. #       offset - offset to start searching
  23. # Return:   None if failure
  24. #       String since found string
  25. # Remarks:  none
  26.  
  27. def strstr(sourcestring, searchstring, offset = 0):
  28.     pos = sourcestring.find(searchstring, offset)
  29.     if pos < 0:
  30.             return None
  31.     else:
  32.         return sourcestring[pos:]
  33.  
  34. # Name:     StringBetween
  35. # Function: Get string between two strings
  36. # Parameter:    sourcestring - String in which should be searched
  37. #       beginstring - the first string to determine
  38. #       endstring - the last string to determine
  39. # Return:   None if failure
  40. #       String between the two strings
  41. # Remarks:  none
  42.  
  43. def StringBetween(searchstring, beginstring, endstring):
  44.     start = strstr(searchstring, beginstring)
  45.     if start == None:
  46.         return None
  47.     start = start[len(beginstring):]
  48.     pos = start.find(endstring)
  49.     if pos < 0:
  50.             return None
  51.     else:
  52.         return start[:pos]
Advertisement
Add Comment
Please, Sign In to add comment