From bc0824105a794da5093c24cc24ef02af4649c1a4 Mon Sep 17 00:00:00 2001 From: thurask Date: Mon, 9 Nov 2015 10:44:33 -0500 Subject: [PATCH] initial commit --- .gitattributes | 88 +++++++------------ .gitignore | 224 ++++--------------------------------------------- LICENSE | 15 ++++ MANIFEST.in | 2 + README.rst | 77 +++++++++++++++++ marvin.py | 109 ++++++++++++++++++++++++ marvin.pyproj | 55 ++++++++++++ marvin.sln | 20 +++++ setup.py | 54 ++++++++++++ 9 files changed, 376 insertions(+), 268 deletions(-) create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 README.rst create mode 100644 marvin.py create mode 100644 marvin.pyproj create mode 100644 marvin.sln create mode 100644 setup.py diff --git a/.gitattributes b/.gitattributes index 1ff0c42..de55994 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,63 +1,35 @@ -############################################################################### -# Set default behavior to automatically normalize line endings. -############################################################################### +# Auto detect text files and perform LF normalization * text=auto -############################################################################### -# Set default behavior for command prompt diff. -# -# This is need for earlier builds of msysgit that does not have it on by -# default for csharp files. -# Note: This is only used by command line -############################################################################### -#*.cs diff=csharp +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union -############################################################################### -# Set the merge driver for project and solution files -# -# Merging from the command prompt will add diff markers to the files if there -# are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following -# file extensions to fail to load in VS. An alternative would be to treat -# these files as binary and thus will always conflict and require user -# intervention with every merge. To do so, just uncomment the entries below -############################################################################### -#*.sln merge=binary -#*.csproj merge=binary -#*.vbproj merge=binary -#*.vcxproj merge=binary -#*.vcproj merge=binary -#*.dbproj merge=binary -#*.fsproj merge=binary -#*.lsproj merge=binary -#*.wixproj merge=binary -#*.modelproj merge=binary -#*.sqlproj merge=binary -#*.wwaproj merge=binary +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain -############################################################################### -# behavior for image files -# -# image files are treated as binary by default. -############################################################################### -#*.jpg binary -#*.png binary -#*.gif binary +# Explicitly declare text files you want to always be normalized and converted +# to native line endings on checkout. +*.cpp text +*.hpp text +*.py text -############################################################################### -# diff behavior for common document formats -# -# Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the -# entries below. -############################################################################### -#*.doc diff=astextplain -#*.DOC diff=astextplain -#*.docx diff=astextplain -#*.DOCX diff=astextplain -#*.dot diff=astextplain -#*.DOT diff=astextplain -#*.pdf diff=astextplain -#*.PDF diff=astextplain -#*.rtf diff=astextplain -#*.RTF diff=astextplain +# Denote all files that are truly binary and should not be modified. +*.png binary +*.jpg binary + +# Disregard line endings +* -crlf \ No newline at end of file diff --git a/.gitignore b/.gitignore index b06e864..7041412 100644 --- a/.gitignore +++ b/.gitignore @@ -1,212 +1,16 @@ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ +*.log +*.exe +*.dll +*.pyd +__pycache__ +*.pyc +dist/ +*.egg-info build/ -bld/ -[Bb]in/ -[Oo]bj/ - -# Visual Studio 2015 cache/options directory +.settings/ +venv/ .vs/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUNIT -*.VisualState.xml -TestResult.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# DNX -project.lock.json -artifacts/ - -*_i.c -*_p.c -*_i.h -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# JustCode is a .NET coding add-in -.JustCode - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -_NCrunch_* -.*crunch*.local.xml - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -## TODO: Comment the next line if you want to checkin your -## web deploy settings but do note that will include unencrypted -## passwords -#*.pubxml - -*.publishproj - -# NuGet Packages -*.nupkg -# The packages folder can be ignored because of Package Restore -**/packages/* -# except build/, which is used as an MSBuild target. -!**/packages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/packages/repositories.config - -# Windows Azure Build Output -csx/ -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!*.[Cc]ache/ - -# Others -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.pfx -*.publishsettings -node_modules/ -orleans.codegen.cs - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -*.mdf -*.ldf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings - -# Microsoft Fakes -FakesAssemblies/ - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# LightSwitch generated files -GeneratedArtifacts/ -_Pvt_Extensions/ -ModelManifest.xml +.cache/ +/.cache/v/cache +/.cache/v/cache/lastfailed +*.user diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a2b8d7e --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. + + http://www.wtfpl.net/ diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..b1eaf85 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.rst +include LICENSE \ No newline at end of file diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..ff90b3d --- /dev/null +++ b/README.rst @@ -0,0 +1,77 @@ +README +====== + +A Python 2/3 script that opens a specific/random entry on the SCP Foundation wiki. + +If you don't know what that is, `give it a shot `__. + +Requirements +------------ + +Python 2.7 or Python 3.2+. Everything is inside the standard library. + +To install, get it from pip: + +:: + + > pip install scp-marvin + +Note: this command may be different depending on your system. Research beforehand. + +Alternatively, just clone the git repo/download the source and install with setuptools: + +:: + + > python setup.py install + +Once you've done that, access it through the ``marvin`` command. + +Command Line Arguments +---------------------- + +Help +~~~~ + +:: + + > marvin -h + + usage: marvin [-h] [-v] [-r] [scp] + + Opens an SCP entry on the SCP Foundation wiki. + + positional arguments: + scp SCP entry ID + + optional arguments: + -h, --help show this help message and exit + -v, --version show program's version number and exit + -r, --random Open a random entry + + http://github.com/thurask/marvin + +Examples +~~~~~~~~ + +:: + + > marvin 173 + + > marvin scp-2998 + + > marvin 789-j + +would open `SCP-173 `__, `SCP-2998 `__ and `SCP-789-J `__, respectively. + +:: + + > marvin -r + +would open a random article. + +License +------- +Copyright 2015 Thurask +This work is free. You can redistribute it and/or modify it under the +terms of the Do What The Fuck You Want To Public License, Version 2, +as published by Sam Hocevar. See the LICENSE file for more details. diff --git a/marvin.py b/marvin.py new file mode 100644 index 0000000..4a56401 --- /dev/null +++ b/marvin.py @@ -0,0 +1,109 @@ +from __future__ import print_function # py2 +import webbrowser # browser +import argparse # arguments +import sys # arguments +try: # py3 + from urllib.request import urlopen + from urllib.error import HTTPError +except ImportError: # py2 + from urllib import urlopen + from urllib2 import HTTPError + + +"""Open a given/random SCP entry on the SCP Foundation wiki.""" + +__author__ = "Thurask" +__license__ = "WTFPL v2" +__copyright__ = "Copyright 2015 Thurask" + + +def grab_entry(entryid): + """ + Open browser if entry exists/tell user entry does not exist. + + :param entryid: Entry ID. + :type entryid: str + """ + entryid = clean_entry_id(entryid) + baseurl = "http://scp-wiki.net/" + str(entryid) + try: + req = urlopen(baseurl) + except HTTPError: + print("{} NOT FOUND".format(entryid.upper())) + raise SystemExit + else: + if entry_exists(req.read().decode("utf-8")): + webbrowser.open(baseurl) + else: + print("{} NOT FOUND".format(entryid.upper())) + + +def clean_entry_id(entryid): + """ + Clean up entry ID. + + :param entryid: Entry ID. + :type entryid: str + """ + entryid = str(entryid).lower() + if entryid is None: + print("NO SCP SPECIFIED") + raise SystemExit + elif not entryid.startswith(("scp-", "spc-")): + entryid = "scp-" + entryid + return entryid + + +def entry_exists(entry): + """ + Check if entry exists. + + :param entry: Text of entry, scraped from the wiki. + :type entry: str + """ + return not "This page doesn't exist yet!" in entry + + +def open_random(): + """ + Open a random entry. + """ + webbrowser.open("http://www.scp-wiki.net/random:random-scp") + + +def grab_args(): + """ + Parse argparse arguments. + """ + parser = argparse.ArgumentParser( + prog="marvin", + description="Opens an SCP entry on the SCP Foundation wiki.", + epilog="http://github.com/thurask/marvin") + parser.add_argument( + "-v", + "--version", + action="version", + version="%(prog)s 1.0.0") + parser.add_argument( + "-r", + "--random", + dest="random", + help="Open a random entry", + action="store_true", + default=False) + parser.add_argument("scp", + help="SCP entry ID", + nargs="?", + default=None) + args = parser.parse_args(sys.argv[1:]) + if args.random: + open_random() + elif not args.random and args.scp is None: + print("NO SCP SPECIFIED") + raise SystemExit + else: + grab_entry(args.scp) + + +if __name__ == "__main__": + parse_args() diff --git a/marvin.pyproj b/marvin.pyproj new file mode 100644 index 0000000..b772a01 --- /dev/null +++ b/marvin.pyproj @@ -0,0 +1,55 @@ + + + + Debug + 2.0 + 8789bbf0-19db-425f-9e0b-2875edf9752e + . + marvin.py + + + . + . + marvin + marvin + {9a7a9026-48c1-4688-9d5d-e5699d47d074} + 3.5 + + + true + false + + + true + false + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/marvin.sln b/marvin.sln new file mode 100644 index 0000000..d797f48 --- /dev/null +++ b/marvin.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "marvin", "marvin.pyproj", "{8789BBF0-19DB-425F-9E0B-2875EDF9752E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8789BBF0-19DB-425F-9E0B-2875EDF9752E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8789BBF0-19DB-425F-9E0B-2875EDF9752E}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9e2b33a --- /dev/null +++ b/setup.py @@ -0,0 +1,54 @@ +from setuptools import setup, find_packages + + +def readme(): + """ + Read ReST readme file, use as long description. + """ + with open('README.rst') as file: + return file.read() + + +setup(name='scp-marvin', + version='1.0.0', + description='SCP Wiki entry retrieval script', + long_description=readme(), + url='http://github.com/thurask/marvin', + author='Thurask', + author_email='thuraski@hotmail.com', + license='WTFPL', + classifiers=[ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Environment :: MacOS X", + "Environment :: Win32 (MS Windows)", + "Environment :: X11 Applications", + "Intended Audience :: End Users/Desktop", + "License :: Freely Distributable", + "Operating System :: MacOS", + "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft", + "Operating System :: Microsoft :: Windows", + "Operating System :: OS Independent", + "Operating System :: POSIX", + "Operating System :: POSIX :: BSD :: FreeBSD", + "Operating System :: POSIX :: BSD :: NetBSD", + "Operating System :: POSIX :: BSD :: OpenBSD", + "Operating System :: POSIX :: Linux", + "Operating System :: Unix", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.2", + "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Topic :: Utilities" + ], + packages=find_packages(), + zip_safe=False, + include_package_data=True, + entry_points={ + 'console_scripts': [ + 'marvin=marvin:grab_args'] + })