Skip to content

Commit

Permalink
Merge branch 'master' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
tranlv committed Jan 15, 2018
2 parents 123f8c7 + beeb272 commit f6011af
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.idea/**
env
**.pyc
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ script: python tests/test_all_of_the_units.py
branches:
only:
- master

install:
- pip install -r requirements.txt

Expand Down
6 changes: 3 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright {yyyy} {name of copyright owner}
Copyright [yyyy] [name of copyright owner]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -198,4 +198,4 @@
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ A web-scraping application to find the minimum number of links between 2 given w
Usage
---

- Set up database management: as of 14 January 2018, Wiki-link has been tested with [Mysql](https://www.mysql.com/downloads/). Alternatively, for quick development setup, I strongly recommend to setup database with [Docker](https://www.docker.com/).
- Set up database management: as of 14 January 2018, Wiki-link has been tested with [Mysql](https://www.mysql.com/downloads/) and [PostgreSQL](https://www.postgresql.org/) (with psycopg2 adapter). Alternatively, for quick development setup, I strongly recommend to setup database with [Docker](https://www.docker.com/).

- Download a [release](https://github.com/tranlyvu/wiki-link/releases) or fork the source code:
- Download a [release](https://github.com/tranlyvu/wiki-link/releases) or fork the repo:

```
$git clone https://github.com/tranlyvu/wiki-link.git
Expand All @@ -24,7 +24,7 @@ $git clone https://github.com/tranlyvu/wiki-link.git
$vi wiki-link/conf.ini
```

- The simplest way is to run the [Sample file](https://github.com/tranlyvu/wiki-link/blob/master/sample.py) with your desired wiki links:
- The simplest way is to run the [sample file](https://github.com/tranlyvu/wiki-link/blob/master/sample.py) with your desired wiki links:

```
$vi wiki-link/sample.py
Expand All @@ -51,11 +51,12 @@ To do
Release History
---

* 1.0.1 - Jan 14, 2018
* v1.0.1 - Jan 14, 2018
* Fix database connection bug
* Test PostgreSQL database

* 1.0.0 - Nov 7, 2016
* The first official release
* v1.0.0 - Nov 7, 2016
* First official release

---
Contribution
Expand All @@ -66,11 +67,11 @@ For bug reports or requests please submit an [issue](https://github.com/tranlyvu
For new features contribution, please follow the following instruction:

```
1. Fork the source code (`$git clone https://github.com/tranlyvu/wiki-link.git`)
1. Fork the repo (`$git clone https://github.com/tranlyvu/wiki-link.git`)
2. Create your feature branch (`$git checkout -b new/your-feature`)
3. Commit your changes (`$git commit -am 'Add some new feature'`)
4. Push to the branch (`$git push origin new/your-feature`)
5. Create a new [Pull Request](https://github.com/tranlyvu/wiki-link/pulls)
5. Create a new Pull Request at https://github.com/tranlyvu/wiki-link/pulls
```

---
Expand Down
12 changes: 10 additions & 2 deletions conf.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[database]
# Database connection, i.e mysql://root:[email protected]:32771
connection = mysql://root:13061990@localhost:3306
# Database connection, examples:
#
# FOR MYSQL:
# connection = mysql://root:12345@localhost:3306
#
# FOR POSTGRES:
# postgresql+psycopg2://postgres:12345@localhost:5432
#
# Change [DATABASE], [NAME], [PASSWORD], [IP], [PORT] with your own connection
connection = [DATABASE]://[NAME]:[PASSWORD]@[IP]:[PORT]
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ beautifulsoup4==4.6.0
bs4==0.0.1
certifi==2017.4.17
chardet==3.0.4
configparser==3.5.0
idna==2.5
mysqlclient==1.3.12
psycopg2==2.7.3.2
requests==2.17.3
six==1.11.0
SQLAlchemy==1.2.0
SQLAlchemy-Utils==0.32.21
urllib3==1.21.1
virtualenv==15.0.3
10 changes: 10 additions & 0 deletions tests/test_wiki_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import unittest

class TestGetDatabaseUrl(unittest.TestCase):
"""
Test get_database_url function
To do
"""

if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions wikilink/wiki_link.ini

This file was deleted.

21 changes: 12 additions & 9 deletions wikilink/wiki_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sqlalchemy.orm import sessionmaker
import os
import sys
from sqlalchemy_utils import functions

Base = declarative_base() # metadata

Expand Down Expand Up @@ -57,16 +58,18 @@ def __init__(self, starting_url, ending_url, limit=6):

new_db_name = 'wikilink'
db_conn_format = get_database_url()
engine = create_engine(db_conn_format, echo=True)
engine.execute("CREATE DATABASE IF NOT EXISTS %s" % new_db_name)
wikilink_engine = create_engine(db_conn_format + "/" + new_db_name, echo=True)
# If table don't exist, Create.
if not wikilink_engine.dialect.has_table(wikilink_engine, 'link'):
if not wikilink_engine.dialect.has_table(wikilink_engine, 'page'):
Base.metadata.create_all(wikilink_engine)
engine = create_engine(db_conn_format + "/" + new_db_name, echo=True)

self.session = sessionmaker(bind=engine)()

Session = sessionmaker(wikilink_engine)
self.session = Session() # having conversation with database
if not functions.database_exists(db_conn_format + "/" + new_db_name):
self.session.connection().connection.set_isolation_level(0)
self.session.execute("CREATE DATABASE %s;" % new_db_name)
self.session.connection().connection.set_isolation_level(1)

# If table don't exist, Create.
if (not engine.dialect.has_table(engine, 'link') and not engine.dialect.has_table(engine, 'page')):
Base.metadata.create_all(engine)

self.limit = limit
self.starting_url = starting_url
Expand Down

0 comments on commit f6011af

Please sign in to comment.