Skip to content

Commit 6ca0f1c

Browse files
committed
Initial commit
0 parents  commit 6ca0f1c

30 files changed

+1046
-0
lines changed

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.idea
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
54+
# Environments
55+
.env
56+
.venv
57+
env/
58+
venv/
59+
ENV/
60+
env.bak/
61+
venv.bak/

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
**Requirements:**
2+
```
3+
Python 3.5 or higher
4+
Windows Environment: N/A
5+
```
6+
7+
**Install requirements**
8+
`pip3 install -r requirements.txt`
9+
10+
**Setup configuration**
11+
```
12+
open: config/app.py
13+
HOST = "0.0.0.0"
14+
DEBUG = True / False
15+
PORT = 8000
16+
WORKERS = 4 # workers: Number of processes received before it is respected
17+
```
18+
19+
**RUN sanic**
20+
`python3 run.py`
21+
22+
```
23+
2017-09-25 10:52:54 - (sanic)[DEBUG]:
24+
▄▄▄▄▄
25+
▀▀▀██████▄▄▄ _______________
26+
▄▄▄▄▄ █████████▄ / \
27+
▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Gotta go fast! |
28+
▀▀█████▄▄ ▀██████▄██ | _________________/
29+
▀▄▄▄▄▄ ▀▀█▄▀█════█▀ |/
30+
▀▀▀▄ ▀▀███ ▀ ▄▄
31+
▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌
32+
██▀▄▄▄██▀▄███▀ ▀▀████ ▄██
33+
▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███ ▌▄▄▀
34+
▌ ▐▀████▐███▒▒▒▒▒▐██▌
35+
▀▄▄▄▄▀ ▀▀████▒▒▒▒▄██▀
36+
▀▀█████████▀
37+
▄▄██▀██████▀█
38+
▄██▀ ▀▀▀ █
39+
▄█ ▐▌
40+
▄▄▄▄█▌ ▀█▄▄▄▄▀▀▄
41+
▌ ▐ ▀▀▄▄▄▀
42+
▀▀▄▄▀
43+
44+
2017-09-25 10:52:54 - (sanic)[INFO]: Goin' Fast @ http://0.0.0.0:8000
45+
2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24478]
46+
2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24479]
47+
2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24480]
48+
2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24481]
49+
50+
```
51+
52+
**Register blueprint route**
53+
54+
`NOTE :: if it's a sub directory it must consist a __init__.py
55+
file to be recognize as a package`
56+
57+
```
58+
from sanic import Blueprint
59+
from sanic.response import json
60+
from http import HTTPStatus
61+
62+
""" blueprint module for url handler """
63+
module_name = 'index' # module name to be registered in the blueprint
64+
or just change the 'index' string to get_file_name(__file__)
65+
it uses the current filename as the root url of your api module
66+
module_name = get_file_name(__file__)
67+
68+
method = Blueprint(module_name, url_prefix='/')
69+
70+
""" http code status """
71+
__status = HTTPStatus # status codes library
72+
73+
74+
@method.route("/", methods=['GET'])
75+
async def index(requests):
76+
return json("Welcome to sanic!", __status.OK)
77+
78+
```
79+
80+
**READ MORE:** ``https://github.com/channelcat/sanic/``

config/.gitignore

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
build/
11+
develop-eggs/
12+
dist/
13+
downloads/
14+
eggs/
15+
.eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
wheels/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
MANIFEST
26+
27+
# PyInstaller
28+
# Usually these files are written by a python script from a template
29+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
30+
*.manifest
31+
*.spec
32+
33+
# Installer logs
34+
pip-log.txt
35+
pip-delete-this-directory.txt
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*.cover
46+
.hypothesis/
47+
48+
# Translations
49+
*.mo
50+
*.pot
51+
52+
53+
# Environments
54+
.env
55+
.venv
56+
env/
57+
venv/
58+
ENV/
59+
env.bak/
60+
venv.bak/

config/__init__.py

Whitespace-only changes.

config/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
HOST = "0.0.0.0"
2+
DEBUG = True
3+
PORT = 8000
4+
WORKERS = 4

database/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__pycache__

database/__init__.py

Whitespace-only changes.

database/neo4j/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from neomodel import config
2+
config.DATABASE_URL = 'bolt://neo4j:fullspeed@35.194.124.33:7687' # default
3+
4+
5+
class Configuration:
6+
DATABASE_URL = 'bolt://neo4j:fullspeed@35.194.124.33:7687' # default
7+
8+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from neomodel import (StructuredNode, UniqueIdProperty, RelationshipTo, StringProperty, DateTimeProperty)
2+
from database.neo4j.neomodel.edges.timestamp import EdgeRelationship
3+
from database.neo4j.neomodel.users import Users
4+
from database.neo4j.neomodel.posts import Posts
5+
6+
7+
class Comments(StructuredNode):
8+
uid = UniqueIdProperty()
9+
content = StringProperty(required=True)
10+
author = RelationshipTo(Users, "AUTHOR", model=EdgeRelationship)
11+
post = RelationshipTo(Posts, "COMMENTED_ON", model=EdgeRelationship)
12+
created_at = DateTimeProperty(default_now=True)
13+
updated_at = DateTimeProperty(default_now=True)
14+
deleted_at = DateTimeProperty(required=False, default=None)
15+
16+
def find(self, page=0, per_page=15, **kwargs):
17+
skip = 0 if page <= 1 else page - 1
18+
limit = skip + per_page
19+
order_by = 'created_at'
20+
21+
if "order_by" in kwargs and kwargs['order_by']:
22+
order_by = kwargs['order_by']
23+
if "uid" in kwargs and kwargs['uid']:
24+
return self.find_by_id(uid=kwargs['uid'])
25+
else:
26+
return self.nodes.order_by(order_by).filter(deleted_at__isnull=True)[skip:limit]
27+
28+
def find_by_id(self, uid):
29+
return self.nodes.get(uid=uid, deleted_at__isnull=True)
30+
31+
def save(self, **kwargs):
32+
if "user_id" in kwargs and "post_id" in kwargs:
33+
author = Users().find_by_id(uid=kwargs['user_id'])
34+
post = Posts().find_by_id(uid=kwargs['post_id'])
35+
36+
if author and post and post.author.get().__dict__["uid"] == kwargs['user_id']:
37+
saved_comment = super().save()
38+
self.author.connect(author)
39+
self.post.connect(post)
40+
return saved_comment
41+
else:
42+
raise LookupError("Invalid author or post.")
43+
else:
44+
raise KeyError("Missing required parameters")

0 commit comments

Comments
 (0)