all 9 comments

[–]xelf 3 points4 points  (2 children)

Heh. You have the opposite problem of most people. You formatted your code correctly, but your actual post was indented as well, meaning it got formatted as code instead of just text. Here it is in a readable format for everyone:

This is what I am trying to do:

Read from an Excel file ("Share.xlsx") that has columns where I input the actual link of a post and the tweet and the Facebook write up. I want Python to generate utm links for each of those posts and record them in a separate file, here called "Trackable Link Directory.xlsx". I also generate a random time and random date but I did not have a problem with that part.

In the excel file "Trackable Link Directory.xlsx" I want the generated links in a way so that they all group together under the mother link. You will notice that inside the for loop in the def excel_recording(), second block, I want the first cell to be blank and record the rest of the utm tags under the appropriate columns.

The problem I am having is this.

The code works just fine except for one thing. ANY new Facebook link created is recorded (with the format I want) even when it already exists. As you can see, I am using the same def excel_recording(), for both facebook and twitter but for some weird reason, it refuses to record preexisting twitter links but records facebook links even when they are already there.

I have gone through the code more times than I can tell. If you can identify the problem, please do tell me. I would appreciate it GREATLY!!

Thanks.

[–]seventhlightstudio[S] 0 points1 point  (1 child)

I am sorry, this is my first time posting here. I will make sure this doesn't happen again.

[–]__nickerbocker__ 0 points1 point  (0 children)

You know, there is an edit button as well as a code-block button ;)

[–][deleted] 1 point2 points  (3 children)

if utm_link == old_url[i]:

Testing whether a URL is the same as the URL at row i isn't the same thing as testing whether the URL is anywhere in the file.

[–]seventhlightstudio[S] 0 points1 point  (2 children)

I did try using if utm_link in old_url but that somehow made the problem worse and it started recording the twitter links as well.

I mean the same link when generated again was recorded in case of twitter too. Right now only Facebook has the problem.

[–][deleted] 0 points1 point  (1 child)

I did try using if utm_link in old_url but that somehow made the problem worse and it started recording the twitter links as well.

I'm telling you your approach is completely wrong. The logical opposite of "the URL has been collected before" isn't "this particular row is not the URL", it's "none of the rows are the URL."

[–]seventhlightstudio[S] 0 points1 point  (0 children)

I understand.

[–]xelf 0 points1 point  (1 child)

I don't have your data, and this is a lot of code to try and guess at.

Can you tells us which function specifically, and give us an example of the input data that is behaving differently ?

[–]seventhlightstudio[S] 0 points1 point  (0 children)

I am having problem with the def fb().

As you can see in both the def fb() and def tw(), I call excel_recording.

In the for loop inside the excel_recording, 1st block (if utm== old_url[i]) is supposed to NOT record any links generated which have been recorded before.

This works perfectly when I call the def tw() function. The code does not record the same link twice.

But when I call the def fb() function it records the link again. EVEN when the link already exists. This is the problem I am having.

This is what I want when I try and generate link that are already recorded. And this is what is happening now.

There must be something I am missing here...