Skip to content
This repository was archived by the owner on Sep 2, 2020. It is now read-only.

Commit 92fa694

Browse files
committed
Initial commit
0 parents  commit 92fa694

16 files changed

+372
-0
lines changed

.gitignore

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Byte-compiled / optimized / DLL files
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+
# Django stuff:
54+
*.log
55+
.static_storage/
56+
.media/
57+
local_settings.py
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/

.travis.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: python
2+
python: 3.6
3+
branches:
4+
only:
5+
- master
6+
install:
7+
- pip install -r requirements.txt
8+
script:
9+
- python3 -m unittest

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Floyd Hightower
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
clean:
2+
rm -rf venv && rm -rf *.egg-info && rm -rf dist && rm -rf *.log* && rm -fr .cache && rm -rf .pytest_cache
3+
4+
venv:
5+
virtualenv -p python3 ~/.virtualenvs/simple_xntwist_ui && . ~/.virtualenvs/simple_xntwist_ui/bin/activate && pip3 install -r requirements.txt
6+
7+
run:
8+
~/.virtualenvs/simple_xntwist_ui/bin/python simple_xntwist_ui/simple_xntwist_ui.py
9+
10+
test: clean
11+
~/.virtualenvs/simple_xntwist_ui/bin/python -m pytest

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: gunicorn simple_xntwist_ui.simple_xntwist_ui:app --log-file=-

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Simple XNTwist UI
2+
3+
[![Build Status](https://travis-ci.org/fhightower/simple-xntwist-ui.svg?branch=master)](https://travis-ci.org/fhightower/simple-xntwist-ui)
4+
5+
Simple demonstration of the XNTwist algorithm using Flask.
6+
7+
## Quick Start
8+
9+
After cloning the repo...
10+
11+
To create a [virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/) for the app, run:
12+
13+
```
14+
make venv
15+
```
16+
17+
Clone the app and run the application at [http://127.0.0.1:5000/](http://127.0.0.1:5000/):
18+
19+
```
20+
make run
21+
```
22+
23+
To test the app, run:
24+
25+
```
26+
make test
27+
```

requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Flask
2+
gunicorn
3+
pytest
4+
xn-twist
5+
xn-twist-python-sdk

runtime.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.6.3

simple_xntwist_ui/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import simple_xntwist_ui
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from flask import flash, Flask, render_template, redirect, request, url_for
5+
from xn_twist import XNTwist
6+
7+
app = Flask(__name__)
8+
app.secret_key = 'abc'
9+
10+
11+
@app.route("/")
12+
def index():
13+
return render_template('index.html')
14+
15+
16+
@app.route("/twist", methods=['POST'])
17+
def twist():
18+
if request.form['domain']:
19+
domain = request.form['domain']
20+
return redirect(url_for('results', domain=domain))
21+
else:
22+
flash('Please enter a domain.', 'error')
23+
return redirect(url_for('index'))
24+
25+
26+
@app.route("/<domain>")
27+
def results(domain):
28+
"""."""
29+
xn = XNTwist()
30+
results = xn.twist(domain, limit=1)
31+
return render_template('results.html', domain=domain, possible_squats=results['possible_squats'], count=results['count'])
32+
33+
34+
35+
if __name__ == '__main__':
36+
app.run(debug=True, use_reloader=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
body {
2+
margin-bottom: 2em;
3+
}
4+
5+
footer {
6+
position: fixed;
7+
left: 0;
8+
bottom: 0;
9+
height: 2em;
10+
width: 100%;
11+
padding-top: 0.35em;
12+
padding-left: 0.5em;
13+
padding-right: 0.5em;
14+
}
15+
16+
/* Styling for growl messages. */
17+
.success-growl {
18+
background-color: #58b957;
19+
font-size: 1.5em;
20+
}
21+
22+
.warning-growl {
23+
background-color: #f2ae43;
24+
font-size: 1.5em;
25+
color: black;
26+
}
27+
28+
.failure-growl {
29+
background-color: #db524b;
30+
font-size: 1.5em;
31+
}
32+
/* End styling for growl messages. */
33+
34+
a {
35+
text-decoration: underline;
36+
/*text-decoration-style: dotted;*/
37+
}
38+
39+
.error {
40+
color: red;
41+
}
42+
43+
.light {
44+
background-color: #f8f8f8;
45+
}
46+
47+
.blue {
48+
background-color: #0072CE;
49+
color: #f8f8f8;
50+
}
51+
52+
.blue:hover {
53+
background-color: #0072CE;
54+
color: #f8f8f8;
55+
}
56+
57+
.dark {
58+
background-color: #222222;
59+
color: #f8f8f8;
60+
}
61+
62+
.dark a {
63+
color: #f8f8f8;
64+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% extends "layout.html" %}
2+
{% block content %}
3+
<form action="{{ url_for('twist') }}" method="POST">
4+
<input type="text" name="domain" maxlength="20">
5+
<input type="submit" class="button blue">
6+
</form>
7+
8+
<br><br>
9+
10+
<a href="{{ url_for('results', domain='example.com') }}">Try 'example.com'</a>
11+
{% endblock %}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<head>
2+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
3+
<meta charset="utf-8">
4+
<title>Simple XNTwist UI</title>
5+
<meta name="description" content="Simple demonstration of the XNTwist algorithm using Flask.">
6+
<meta name="author" content="">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
9+
<!--[if lt IE 9]>
10+
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
11+
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
12+
<![endif]-->
13+
14+
<!-- STYLESHEETS -->
15+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/css/foundation.min.css">
16+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
17+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-jgrowl/1.4.6/jquery.jgrowl.min.css">
18+
<link rel="stylesheet" href="./static/simple_xntwist_ui.css">
19+
20+
<!-- SCRIPTS -->
21+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
22+
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.3.1/js/foundation.min.js"></script>
23+
<!-- <script src="https://cdn.jsdelivr.net/npm/vue"></script> -->
24+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-jgrowl/1.4.6/jquery.jgrowl.min.js"></script>
25+
</head>
26+
27+
<body class="light">
28+
<div class="top-bar blue">
29+
<div class="top-bar-left">
30+
<a class="blue" href="http://demo.xntwist.tk/"><b>Simple XNTwist UI</b></a> - Simple demonstration of the XNTwist algorithm using Flask.
31+
</div>
32+
</div>
33+
34+
<br><br>
35+
36+
<div class="row">
37+
{% block content %}{% endblock %}
38+
</div>
39+
40+
<footer class="large-12 dark">
41+
Designed and written by <a href="https://hightower.space">Floyd Hightower</a>.
42+
43+
<span class="float-right">
44+
View code or raise an issue on <a href="https://github.com/fhightower/ioc-toolkit">Github</a>.
45+
</span>
46+
</footer>
47+
</body>
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "layout.html" %}
2+
{% block content %}
3+
<h1>Results for {{ domain }}</h1>
4+
5+
Found {{ count }} results with a <span data-tooltip aria-haspopup="true" class="has-tip" data-disable-hover='false' tabindex=1 title="The results shown below is only a small sample of the possible output from XNTwist. See xntwist.tk for more information about the algorithm.">limited dataset</span>.
6+
7+
<br><br>
8+
9+
<ul>
10+
{% for squat in possible_squats %}
11+
<li>{{ squat.displayed }} ({{ squat.punycode }})</li>
12+
{% endfor %}
13+
</ul>
14+
15+
{% endblock %}

tests/__init__.py

Whitespace-only changes.

tests/test_simple_xntwist_ui.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import unittest
5+
6+
from simple_xntwist_ui import simple_xntwist_ui
7+
8+
9+
class SimpleXntwistUiTestCase(unittest.TestCase):
10+
11+
def setUp(self):
12+
self.app = simple_xntwist_ui.app.test_client()
13+
14+
def test_get_index(self):
15+
rv = self.app.get('/')
16+
self.assertIn('Simple XNTwist UI', rv.data.decode())
17+
self.assertIn('Simple demonstration of the XNTwist algorithm using Flask.', rv.data.decode())
18+
self.assertIn('Welcome!', rv.data.decode())
19+
self.assertIn('This is the start of something great.', rv.data.decode())

0 commit comments

Comments
 (0)