Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature db #75

Merged
merged 8 commits into from
Aug 5, 2018
Merged

Feature db #75

merged 8 commits into from
Aug 5, 2018

Conversation

tiagoCMatias
Copy link
Contributor

#47
Created a simple .env file in root folder and another in modules named savedb.py, also added a new argument when starting the program.
Basically, the operations needed is:

edit the .env file with the credentials to access the database
start the script with -db like this: torBot.py -db -u URL
The program will run and in the end, it will store all the links in a table

Copy link
Member

@PSNAppz PSNAppz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR. Good work.

@PSNAppz
Copy link
Member

PSNAppz commented Mar 22, 2018

@tiagoCMatias Could you create a test case for the same?

@tiagoCMatias
Copy link
Contributor Author

@PSNAppz I will give my best to provide tests 👍

password = password of MYSQL
link = URLs from the crawler
"""
if database and user and password is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think (True is None or False is None) going to evaluate to False and hence in else loop???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just to prevent null values and exits with a message... This can be improved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you switch it to if not database and not user and not password?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, ofc... report here all the necessary refactoring and in aprox. a week I will commit all the changes


#Debug
#print("Database:", database, "\nuser:",user, "\npass:",password)
db = MySQLdb.connect(host="localhost", # your host
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if connection doesn't happen, error is not caught.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it is true. What would the best fix? a try expect block with a raise in case of error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, try expect will do

#print(query)
db.commit()

except (MySQLdb.Error, MySQLdb.Warning) as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of the errors invoke the same actions, you can put them all on one line such as
except (MySQLdb.Error, MySQLdb.Warning, TypeError, ValueError) as e

cur.close()
db.close()
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have a blank except right here? You can just use one try-except block instead of a nested one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested try is to separate errors. You can get an error for not being able to connect to database, or get an error for not being able to insert data into the table

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes there should be two completely separate try excepts. for example:

try:
    db = MySQLdb.connect(...)
    cur = db.cursor()
except:
    print("Unable to connect to database")

try:
    query = ...
except (MySQLdb.Error, MySQLdb.Warning, TypeError, ValueError) as e:
   print(e)```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks... Nice tip, didn't thought of it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I just thought it'd make sense to separate the connection logic from the actual querying logic. Plus if you want blank exceptions to cover as little code as possible since it can be triggered by any error.


except (MySQLdb.Error, MySQLdb.Warning, TypeError, ValueError) as e:
print(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not raise error instead of printing and returning None?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't considering raising an error for this... If you can't save to the database and raise an error the program will stop... If that is a requirement I can change it but in my opinion, a simple message is better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a requirement, I was just curious. It's fine as it is though :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KingAkeem want me to raise an error if unable to write to the table??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, printing is fine. If we find a need to raise errors over using print statements then we will.

@PSNAppz
Copy link
Member

PSNAppz commented Mar 29, 2018

@tiagoCMatias Are you still on it? Please see the requested changes. You can join our slack channel for discussions. Please post your email below to send an invitation.

Copy link
Contributor

@agrepravin agrepravin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test cases?? @PSNAppz don't merge unless have extensive test cases, becomes difficult at later point revisiting and writing them

Copy link
Contributor

@agrepravin agrepravin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please implement requested chnages

@tiagoCMatias
Copy link
Contributor Author

Yes, I'm still implementing changes... I have other works in my hands right now that's why I'm taking so long to submit new changes. I will try to commit as soon as I can


except (MySQLdb.Error, MySQLdb.Warning, TypeError, ValueError) as e:
print(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a requirement, I was just curious. It's fine as it is though :)

Copy link
Member

@KingAkeem KingAkeem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good 👍

@tiagoCMatias
Copy link
Contributor Author

I will start writing tests for this but I will not post it in this issue... maybe open another?

@PSNAppz
Copy link
Member

PSNAppz commented Apr 2, 2018

@tiagoCMatias Well I recommend you push the tests here in this branch itself.

@PSNAppz
Copy link
Member

PSNAppz commented Apr 23, 2018

@tiagoCMatias Please let me know the status on this PR?

@KingAkeem
Copy link
Member

Could you please give a status update? If not, your PR will be closed within 48 hours.

@PSNAppz
Copy link
Member

PSNAppz commented Jul 8, 2018

@KingAkeem Should we merge this?

@PSNAppz PSNAppz added this to the TorBot v1.3 milestone Jul 8, 2018
@KingAkeem
Copy link
Member

@PSNAppz If you've tested it and it works fine then yes we can merge it.

@agrepravin
Copy link
Contributor

@tiagoCMatias Merge conflicts needs to resolved? Can you please solve them.

@tiagoCMatias
Copy link
Contributor Author

Sorry guys, I'm currently busy and didn't have the time to look at this

@PSNAppz
Copy link
Member

PSNAppz commented Jul 22, 2018

@tiagoCMatias It’s ok. Someone else can work on this PR and commit this as it is a mandatory feature.

@PSNAppz
Copy link
Member

PSNAppz commented Aug 5, 2018

@tiagoCMatias Thank you for the feature. 👏

@PSNAppz PSNAppz merged commit e2e7690 into DedSecInside:dev Aug 5, 2018
KingAkeem added a commit that referenced this pull request Aug 19, 2018
This reverts commit e2e7690, reversing
changes made to 8c7263b.
KingAkeem added a commit that referenced this pull request Aug 19, 2018
Revert "Merge pull request #75 from tiagoCMatias/feature-db"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants