Skip to content

Commit

Permalink
Change navbar color, other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amitt001 committed Jun 22, 2019
1 parent d15f631 commit 70a854d
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 47 deletions.
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,35 @@ Live version of this project @ [https://pygy.co](https://pygy.co)

Check link stats by adding **+** to the URL. Example [pygy.co/pygmy+](https://pygy.co/pygmy+)

Hackernews Thread: [https://news.ycombinator.com/item?id=17690559](https://pygy.co/shorten/pygmyHN)

*Note that pygy.co is a demo website for this project and should be used as such. While the website is going to be up for the foreseeable future, its future depends on the sponsorship and hosting that I get. Currently, the project is hosted on Digitalocean, as they were kind enough to offer me one year of sponsorship. I would like to keep the project website up and maintain the project but I do not make any financial gains out of this project or website. Website is
free to use and is completely ad-free.
If you would like to support the project, Please use the donate link in [Donations](#donations) section.*

# Table of Contents
- [Pygmy](#pygmy)
- [Table of Contents](#table-of-contents)
- [Features](#features)
- [Technical Info](#technical-info)
- [Installation/Setup](#installationsetup)
- [Docker](#docker)
- [Manual(from source)](#manualfrom-source)
- [DB Setup:](#db-setup)
- [Use MySQL](#use-mysql)
- [Use Postgresql](#use-postgresql)
- [Use SQLite](#use-sqlite)
- [Docker](#docker-1)
- [Using Pygmy API](#using-pygmy-api)
- [Create User:](#create-user)
- [Shell Usage](#shell-usage)
- [How Link Stats Are Generated?](#how-link-stats-are-generated)
- [How Pygmy Auth Token Works?](#how-pygmy-auth-token-works)
- [Development](#development)
- [Contributions](#contributions)
- [Donations](#donations)
- [Sponsorship](#sponsorship)
- [License](#license)
- [Pygmy](#Pygmy)
- [Table of Contents](#Table-of-Contents)
- [Features](#Features)
- [Technical Info](#Technical-Info)
- [Installation/Setup](#InstallationSetup)
- [Docker](#Docker)
- [Manual(from source)](#Manualfrom-source)
- [DB Setup:](#DB-Setup)
- [Use MySQL](#Use-MySQL)
- [Use Postgresql](#Use-Postgresql)
- [Use SQLite](#Use-SQLite)
- [Docker](#Docker-1)
- [Using Pygmy API](#Using-Pygmy-API)
- [Create User:](#Create-User)
- [Shell Usage](#Shell-Usage)
- [How Link Stats Are Generated?](#How-Link-Stats-Are-Generated)
- [How Pygmy Auth Token Works?](#How-Pygmy-Auth-Token-Works)
- [Development](#Development)
- [Contributions](#Contributions)
- [Donations](#Donations)
- [Sponsorship](#Sponsorship)
- [License](#License)

Pygmy or `pygy.co` is an open-source, extensible & easy-to-use but powerful URL shortener. It's created keeping in mind that it should be easy to host and run your custom URL shortener without much effort. [Open-source Python URL shortener]

Expand Down
2 changes: 1 addition & 1 deletion pygmy/app/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def shorten(long_url, short_code=None, expire_after=None, description=None,
secret_key=None, owner=None, request=None):
"""Helper class that has been delicated the task of inserting the
"""Helper class that has been deligated the task of inserting the
passed url in DB, base 62 encoding from db id and return the short
url value.
Expand Down
14 changes: 7 additions & 7 deletions pygmy/rest/shorturl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ def get(self):
def post(self):
payload = request.get_json()
data, errors = self.schema.load(payload)

if errors:
log.error('Error in the request payload %s', errors)
if errors.get('long_url'):
errors.update({'error': errors.get('long_url')})
return jsonify(errors), 400

# if authenticated request check valid user
user_email = APITokenAuth.get_jwt_identity()
if user_email:
user = UserManager().find(email=user_email)
if not user:
return jsonify(dict(error='Invalid user')), 400
data['owner'] = user.id
if errors:
log.error('Error in the request payload %s', errors)
if errors.get('long_url'):
errors.update({'error': errors.get('long_url')})
return jsonify(errors), 400

long_url = data.pop('long_url')
log.info('Shortening url %s', long_url)
Expand Down Expand Up @@ -90,8 +92,6 @@ def get(self):
@APITokenAuth.token_optional
def resolve(code):
"""Resolve the short url. code=301 PERMANENT REDIRECTION"""
# TODO not needed
user_email = APITokenAuth.get_jwt_identity()
secret_key = request.headers.get('secret_key')
try:
# check if link is not a secret link
Expand Down
4 changes: 1 addition & 3 deletions pygmy/validator/link.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import string

from datetime import datetime
from marshmallow import (
Schema, fields, post_dump, validate, ValidationError)
from marshmallow import Schema, fields, post_dump, ValidationError

from pygmy.model.clickmeta import ClickMetaManager
from pygmy.utilities.urls import make_short_url, validate_url
Expand Down Expand Up @@ -50,7 +49,6 @@ class LinkSchema(Schema):
created_at = fields.DateTime(format='%Y-%m-%d %H:%M:%S', dump_only=True)
updated_at = fields.DateTime()


def short_url_path(self, link):
if link and link.short_code:
return make_short_url(link.short_code)
Expand Down
13 changes: 7 additions & 6 deletions pygmyui/pygmy/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import string
import operator

Expand All @@ -8,7 +9,7 @@
from utils import pygmy_client_object
from restclient.errors import ObjectNotFound, UnAuthorized, LinkExpired, \
InvalidInput
from restclient.error_msg import *
from restclient.error_msg import API_ERROR, INVALID_TOKEN
from iso2full import iso2full

# TODO: [IMP] middleware to return 500 page when internal error occurs.
Expand Down Expand Up @@ -112,15 +113,15 @@ def short_link_stats(request, code):
pygmy_client = pygmy_client_object(settings, request)
if request.method == 'GET':
try:
clickmeta = pygmy_client.link_stats(code)
clickmeta = pygmy_client.link_stats(code)
clickmeta['country_stats'] = sorted(
clickmeta['country_stats'].items(),
key=operator.itemgetter(1),
reverse=True)
stats =[(country,iso2full.get(country,"unknown"),hits) for (country,
hits) in clickmeta['country_stats']]
clickmeta['country_stats'] = stats

country_stats = [(country, iso2full.get(country, "unknown"), hits)
for (country, hits) in clickmeta['country_stats']]
clickmeta['country_stats'] = country_stats

clickmeta['referrer'] = sorted(
clickmeta['referrer'].items(),
Expand Down
2 changes: 1 addition & 1 deletion pygmyui/restclient/error_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def API_ERROR(error_message):
pass
elif isinstance(error_message, dict):
error_message = error_message.get('error')
except Exception as e:
except Exception:
import traceback
traceback.print_exc()
error_message = INTERNAL_SERVER_ERROR_API
Expand Down
5 changes: 1 addition & 4 deletions pygmyui/static/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ body {
margin-right: .2px;
}

a {
}

ul.dropdown-lr {
width: 300px;
}
Expand Down Expand Up @@ -112,7 +109,7 @@ margin-top: 3%;
.navbar .nav > li > a:focus,
.navbar .nav > li > a:active,
.navbar .nav > li > a:visited {
background-color: #44EEBB;
background-color: #599B36;
}

.item-detail-title {
Expand Down
2 changes: 1 addition & 1 deletion pygmyui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<meta name="keywords" content="Pygmy,URL Shortener,pygy,pygyco,open source url shortener,python url shortener">
</head>
<body>
<nav class="navbar navbar-light navbar-fixed-top" role="navigation" style="background-color:#095d57">
<nav class="navbar navbar-light navbar-fixed-top" role="navigation" style="background-color:#6FBF45">
<!--#00FA9A;">-->
<div class="container-fluid">
<div class="navbar-header">
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ certifi==2018.1.18
cffi==1.11.4
chardet==3.0.4
click==6.7
Django==2.2.1
Django==2.2.2
Flask==1.0.2
Flask-Cors==3.0.3
Flask-JWT-Extended==3.6.0
Expand All @@ -28,4 +28,4 @@ requests==2.22.0
six==1.11.0
SQLAlchemy==1.3.3
urllib3==1.25.3
Werkzeug==0.14.1
Werkzeug==0.14.1
1 change: 1 addition & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.3

0 comments on commit 70a854d

Please sign in to comment.