1

I am using some code that takes advantage of webbrowser pkg to follow a link in Python and download data. Within the link the date is referred to multiple times in format DDMMMYY (ie. 24Jul19) - I am using the code to make sure the date refers to today properly, so when I start the code it prompts the user to enter yest's date, (in this case 23Jul19) and scans the link for all instances of this date, then replaces it with 24Jul19, so that I now how the proper link for today's date. This seems to work fine (all instances of 23Jul19 change to 24Jul19 without issue), but for some reason it alters a completely different piece of the link which leads me to downloading blank data fields.

The links are all stored as strings within a text file that is read into python. The program first prompts the user to enter yesterday's date, and enter today's date. When the program is closed, it writes back the link with the new dates, but adds a totally different change to the code, and I am not sure what's happening here.

Date = raw_input("Enter Today's Date (DDMMMYY): ")
Date_Yest = raw_input("Enter Previous Date (DDMMMYY): ")

x = []
with open("links.txt") as f:
 for l in f:
    x.append(l.strip())
for i in x:
if 'A' in i:
    A_file = i
if 'B' in i:
    B_file = i

and then I am using the replace function as such:

with open('Loan_links.txt','w') as text_file:
text_file.write(A_file+"\n")
text_file.write("\n")
text_file.write(B_file+"\n")

The original link (without providing private details) looks something like this :

...ignorecolumns=Model+Calc%2C&param0=64192&param1=USER&param2=23Jul19&param3=23Jul19...

When the program runs, the dates in the portion of the link properly change from 23Jul19 to 24Jul19, BUT before the place that says "ignorecolumns" it adds a whole other string of words that aren't in the first link at all. I'm not sure if this has something to do with the way to code is interacting with the weblink itself through the browser. But I have ZERO clue why or how there are so many characters being added to this link. It is all valid words, info, etc., but not included in the original link in the text file AT ALL. It adds:

...allreplacementcolumnnames=Offer%3DClose+Offer%2CBid%3DClose+Bid%2CDepth%3DClose+Depth%2C...

It's obviously financial data I'm working with here, but for privacy's sake that's all I can expand on link wise. Any idea what would cause the link to add a ton of extra text in general?

ncica
  • 7,015
  • 1
  • 15
  • 37
jod51
  • 111
  • 1
  • 2
  • 13
  • What is happening in the first code block? What are A_file and B_file for? Also, where did you use the replace function? I don't see it in the code you have shared. – Samik Jul 24 '19 at 18:56

0 Answers0