LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2017, 09:34 PM   #1
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 282

Rep: Reputation: 30
Best/Easiest way to implement a Python script as a webpage?


I have a Python script that takes an encoded URL from Proofpoint and decodes it. You call it with the encoded URL as an argument. I want to be able to have a very simple webpage on a server that just has an input box for the URL and underneath is the decoded output. I'm thinking of trying to implement it with Nginx+FastCGI maybe? Are there easier ways to do this as a non-coder? Thanks.

Code:
#!python

import sys
import re
import urllib.parse
import html.parser

def main():
	rewrittenurl = sys.argv[1]
	match = re.search(r'https://urldefense.proofpoint.com/(v[0-9])/', rewrittenurl)
	if match:
		if match.group(1) == 'v1':
			decodev1(rewrittenurl)
		elif match.group(1) == 'v2':
			decodev2(rewrittenurl)
		else:
			print('Unrecognized version in: ', rewrittenurl)
			
	else:
		print('No valid URL found in input: ', rewrittenurl)
		
def decodev1 (rewrittenurl):
	match = re.search(r'u=(.+?)&k=',rewrittenurl)
	if match:
		urlencodedurl = match.group(1)
		htmlencodedurl = urllib.parse.unquote(urlencodedurl)
		url = html.parser.HTMLParser().unescape(htmlencodedurl)
		print(url)
	else:
		print('Error parsing URL')

def decodev2 (rewrittenurl):
	match = re.search(r'u=(.+?)&[dc]=',rewrittenurl)
	if match:
		specialencodedurl = match.group(1)
		trans = str.maketrans('-_', '%/')
		urlencodedurl = specialencodedurl.translate(trans)
		htmlencodedurl = urllib.parse.unquote(urlencodedurl)
		url = html.parser.HTMLParser().unescape(htmlencodedurl)
		print(url)
	else:
		print('Error parsing URL')
		
if __name__ == '__main__':
    main()
 
Old 08-24-2017, 09:44 PM   #2
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Haven't done this myself, but these may be useful links:

https://fragments.turtlemeat.com/pythonwebserver.php
https://stackoverflow.com/questions/...te-with-python
 
Old 08-25-2017, 01:35 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
additionally you can try flask: https://www.fullstackpython.com/flask.html
(and there are a lot of other possibilities)
 
Old 08-25-2017, 02:24 AM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
Flask is a good option. This is another one, fairly similar to Flask:

http://bottlepy.org/docs/dev/

Last edited by dugan; 08-25-2017 at 02:38 AM.
 
Old 08-25-2017, 07:45 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,649
Blog Entries: 4

Rep: Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934Reputation: 3934
Django. Easily the best.

"The web framework for perfectionists with deadlines.™"
 
  


Reply

Tags
python, webpage



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Learning Python, how should I implement the following problem in Python 3 code? rblampain Programming 8 05-29-2016 10:53 AM
easiest linux python ide sigint-ninja Linux - Newbie 16 11-04-2013 01:55 PM
[SOLVED] Python : implement a Keypress Left/Right Xeratul Programming 6 10-27-2011 03:02 PM
Easiest way to implement sending to a POP3 server NateTut Linux - Newbie 7 05-19-2009 03:04 PM
python webpage master Programming 5 11-20-2005 02:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration