__id__
int64
3.09k
19,722B
blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
2
256
content_id
stringlengths
40
40
detected_licenses
list
license_type
stringclasses
3 values
repo_name
stringlengths
5
109
repo_url
stringlengths
24
128
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringlengths
4
42
visit_date
timestamp[ns]
revision_date
timestamp[ns]
committer_date
timestamp[ns]
github_id
int64
6.65k
581M
star_events_count
int64
0
1.17k
fork_events_count
int64
0
154
gha_license_id
stringclasses
16 values
gha_fork
bool
2 classes
gha_event_created_at
timestamp[ns]
gha_created_at
timestamp[ns]
gha_updated_at
timestamp[ns]
gha_pushed_at
timestamp[ns]
gha_size
int64
0
5.76M
gha_stargazers_count
int32
0
407
gha_forks_count
int32
0
119
gha_open_issues_count
int32
0
640
gha_language
stringlengths
1
16
gha_archived
bool
2 classes
gha_disabled
bool
1 class
content
stringlengths
9
4.53M
src_encoding
stringclasses
18 values
language
stringclasses
1 value
is_vendor
bool
2 classes
is_generated
bool
2 classes
year
int64
1.97k
2.01k
8,022,998,956,157
42f4a98b03d5bb42b3dda79e8d96cd14582d519b
0d51368e5ec93184386d4258386ef79e03b3854d
/coffin/views/generic/list.py
a99af4edcc54ffd6c42e9be36538435c8f1d5ec4
[ "BSD-3-Clause" ]
permissive
Deepwalker/coffin
https://github.com/Deepwalker/coffin
495a9f5cda8f243fa13ed7a15219fa468b6faf30
5313abe5dbae1b32772c8de236e9a667e4822363
refs/heads/master
2021-01-15T20:33:02.541907
2012-04-22T22:44:58
2012-04-22T22:44:58
4,107,705
1
0
null
null
null
null
null
null
null
null
null
null
null
null
null
from django.views.generic.list import ListView as _ListView from coffin.views.decorators import template_response __all__ = ['ListView'] ListView = template_response(_ListView)
UTF-8
Python
false
false
2,012
8,366,596,339,027
68b1f66c4cf0ace84ce1ecdce9484e31304f92dc
89a2bca0dca54b69d38c2df31a4d36afab1344da
/resources/scrapers/showtimes/googleapi/__init__.py
fe381fe99f838226d44e7e9c0291b4a2160ac5c6
[ "CC-BY-NC-4.0", "LicenseRef-scancode-other-copyleft", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-proprietary-license", "LicenseRef-scancode-cc-by-nc-sa-3.0-us", "LicenseRef-scancode-warranty-disclaimer", "CC-BY-NC-SA-3.0" ]
non_permissive
nuka1195/plugin.video.movie_trailers
https://github.com/nuka1195/plugin.video.movie_trailers
e9b8d0639c189306f64332e1638860a56e07a266
8978a9014b605a3f13cdf12a5fb9af23f242ba51
refs/heads/master
2021-01-19T16:50:51.240009
2013-06-20T12:25:44
2013-06-20T12:25:44
null
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
#http://www.google.com/ig/api?movies=15122 from unicodedata import normalize from urllib import quote_plus import StringIO import gzip import os import re import urllib2 #try: # import xbmc #except: # pass class Scraper: """ *REQUIRED: Fetcher Class for www.google.com/movies """ # base url sort=0 theater list BASE_URL = "http://www.google.com/movies?near=%s&sort=%d&date=%d&time=%d&start=%d" """ near = zip code or city sort = (0 theater list, 1 movie list) date = (0 today up to 15) time = (0 all times, 1 morning, 2 afternoon, 3 evening, 4 late) start =(0 increments of 10) """ def __init__(self, Addon=None): self.Addon = Addon # regex's self.regex_movies_list = re.compile("<div class=movie><div class=header><div class=img><img src=\"([^\"]+)\"[^>]+></div><div class=desc[^>]+><h2><a href=\"([^\"]+)\">([^<]+)</a></h2><div class=info>.+?<div class=info>(.+?)<div class=syn>(.+?)<p class=clear>.+?<div class=showtimes>(.+?)<p class=clear>") self.regex_theater_list = re.compile("<div class=theater>.+?<a href=\"([^\"]+)\"[^>]+>([^<]+)</a></div><div class=address>([^<]+)<.+?<div class=times>([^<]+)</div></div>") def fetch_movies(self, _date=0, _time=0, _start=0): # set url url = self.BASE_URL % ("48161", 1, _date, _time, _start) # fetch and parse movies list movies = self._parse_html_source(self._get_html_source(url)) def _get_html_source(self, url): ############################################## return unicode(open("movies.html", "r").read(), "UTF-8") # add headers headers = { "User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)", "Accept": "text/html; charset=UTF-8", "Accept-Encoding": "gzip" } # request url request = urllib2.Request(url, headers=headers) # open requested url usock = urllib2.urlopen(request) # if gzipped, we need to unzip the source, ## ELIMINATE CHECK AS IT's PROBABLY always zipped if (usock.info().getheader("Content-Encoding") == "gzip"): print "ZZZZZZZZZZZZZZZZZZZZIIIIIIIIIIIIIIIIIIIIIPped" source = gzip.GzipFile(fileobj=StringIO.StringIO(usock.read())).read() else: source = usock.read() # close socket usock.close() # return a unicode object return unicode(source, "UTF-8", "replace") def _parse_html_source(self, htmlSource): records = [] """ ( u'/movies/image?tbn=212dd6ba99665f32&amp;size=100x150', u'/movies?near=48161&amp;sort=1&amp;date=0&amp;time=0&amp;mid=4810d65ff64f7659', u'Little Fockers', u'\u200e1hr 38min\u200e\u200e - Rated PG-13\u200e\u200e - Comedy\u200e<br>Director: Paul Weitz - Cast: Robert De Niro, Ben Stiller, Owen Wilson, Blythe Danner, Teri Polo - <nobr><a href="" class=fl></a>: <nobr><img src="/images/sy-star-off.gif" width=10 height=9 border=0 alt="Rated 0.0 out of 5.0"><img src="/images/sy-star-off.gif" width=10 height=9 border=0 alt=""><img src="/images/sy-star-off.gif" width=10 height=9 border=0 alt=""><img src="/images/sy-star-off.gif" width=10 height=9 border=0 alt=""><img src="/images/sy-star-off.gif" width=10 height=9 border=0 alt=""></nobr></nobr></div>', u'It has taken 10 years, two little Fockers with wife Pam and countless hurdles for Greg to finally get &quot;in&quot; with his tightly wound father-in-law, Jack. After the cash-strapped dad takes a job moonlighting for a drug company, however, Jack&#39;s suspicions about his favorite male nurse <span id=MoreAfterSynopsisFirst0 style="display:none"><a href="javascript:void(0)"onclick="google.movies.showMore(\'0\')">more &raquo;</a></span><span id=SynopsisSecond0>come roaring back. When Greg and Pam&#39;s entire clan-including Pam&#39;s lovelorn ex, Kevin-descends for the twins&#39; birthday party, Greg must prove to the skeptical Jack that he&#39;s fully capable as the man of the house. But, with all the misunderstandings, spying and covert missions, will Greg pass Jack&#39;s final test and become the family&#39;s next patriarch... will the circle of trust be broken for good? <span id=LessAfterSynopsisSecond0 style="display:none"><a href="javascript:void(0)"onclick="google.movies.showLess(\'0\')">&laquo; less</a></span></span></div></div>', u'<div class=show_left><div class=theater><div id=theater_6750433078994449928 ><div class=name><a href="/movies?near=48161&amp;sort=1&amp;date=0&amp;time=0&amp;tid=5dae5b1eb982b608" id=link_1_theater_6750433078994449928>Phoenix Theatres The Mall of Monroe</a></div><div class=address>2121 N. Monroe St., Monroe, MI<a href="" class=fl target=_top></a></div></div><div class=times>10:05am&nbsp; 12:00&nbsp; 2:10&nbsp; 4:20&nbsp; 6:35&nbsp; 8:35&nbsp; 10:35pm</div></div><div class=theater><div id=theater_11106351332624381742 ><div class=name><a href="/movies?near=48161&amp;sort=1&amp;date=0&amp;time=0&amp;tid=9a21afb16bc3372e" id=link_1_theater_11106351332624381742>Emagine Woodhaven</a></div><div class=address>21720 Allen Rd., Woodhaven, MI<a href="" class=fl target=_top></a></div></div><div class=times>3:15&nbsp; 5:30&nbsp; 7:50&nbsp; 10:10&nbsp; 11:00pm</div></div></div><div class=show_right><div class=theater><div id=theater_12419587383974457988 ><div class=name><a href="/movies?near=48161&amp;sort=1&amp;date=0&amp;time=0&amp;tid=ac5b3cec86b87284" id=link_1_theater_12419587383974457988>Rave Motion Pictures Franklin Park 16</a></div><div class=address>5001 Monroe Street, Toledo, OH<a href="" class=fl target=_top></a></div></div><div class=times>11:15am&nbsp; 12:00&nbsp; 12:45&nbsp; 1:45&nbsp; 2:30&nbsp; 3:15&nbsp; 4:15&nbsp; 5:00&nbsp; 5:45&nbsp; 6:45&nbsp; 7:30&nbsp; 8:15&nbsp; 9:15&nbsp; 10:00&nbsp; 10:45pm</div></div><div class=theater><div id=theater_13024597489691353394 ><div class=name><a href="/movies?near=48161&amp;sort=1&amp;date=0&amp;time=0&amp;tid=b4c0aa68db7f6132" id=link_1_theater_13024597489691353394>MJR Southgate Digital Cinema 20</a></div><div class=address>15651 Trenton Road, Southgate, MI<a href="" class=fl target=_top></a></div></div><div class=times>10:00&nbsp; 10:40&nbsp; 11:30am&nbsp; 12:30&nbsp; 1:00&nbsp; 2:00&nbsp; 3:00&nbsp; 4:00&nbsp; 4:45&nbsp; 5:30&nbsp; 6:30&nbsp; 7:15&nbsp; 8:00&nbsp; 9:00&nbsp; 9:40&nbsp; 10:30pm</div></div></div>') """ movies = self.regex_movies_list.findall(htmlSource) for movie in movies: info = movie[ 3 ].replace(u"\u200e", "").replace(u"Rated ", "").replace(u"<br>", " - ").replace(u"Director: ", "").replace(u"Cast: ", "").split(" - ") plot = re.sub("<[^>]+>", "", movie[ 4 ].replace("more &raquo;", "").replace("&laquo; less", "")).strip() print movie[ 2 ] print info[ :-1 ] plot += "\n\n" theaters = self.regex_theater_list.findall(movie[ 5 ]) for theater in theaters: plot += "\n".join(theater[ 1 : 4 ]).replace("&nbsp;", " ") + "\n\n" print print plot if __name__ == "__main__": locale = "48161" scraper = Scraper() scraper.fetch_movies()
UTF-8
Python
false
false
2,013
9,234,179,714,977
dc2e7bfbff702b47c3a8c70083b6aca79a345d0d
678844588ee5da0d86fcf4d9b00acdd4ea110805
/bin/buildslave
685d012ab8ea57f176ec752c2dc75df537001289
[ "MIT", "GPL-2.0-only", "BSD-3-Clause", "LicenseRef-scancode-other-copyleft", "ZPL-2.1" ]
non_permissive
hgroll/yocto-autobuilder
https://github.com/hgroll/yocto-autobuilder
8d39ea2666f63a7a06cc84a01caa517f0399935f
d19285aa181279d4505ac980448e8a783518fd11
refs/heads/master
2020-12-25T03:41:41.183977
2013-04-15T23:43:01
2013-04-15T23:43:01
null
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
#!/usr/bin/python # EASY-INSTALL-SCRIPT: 'buildbot-slave==0.8.4','buildslave' __requires__ = 'buildbot-slave==0.8.4' import pkg_resources pkg_resources.run_script('buildbot-slave==0.8.4', 'buildslave')
UTF-8
Python
false
false
2,013
8,521,215,127,828
5d01d06374b688fad31ab83e2ddfe8c6908055f5
0ed1e08539d345b62bded5bf95938cec275fb7f3
/src/event.py
096713b0dcbe79e7d43a066729bed40a5fcdaa52
[]
no_license
Danquebec/Societes
https://github.com/Danquebec/Societes
6fcc4f1f68cb493f0849388db5a6338f5e7b2d5d
ebe79c0f939333d3e76834dae2d8ceed52953699
refs/heads/master
2020-03-26T22:32:38.778869
2014-11-02T22:33:27
2014-11-02T22:33:27
null
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
#!/usr/bin/python # -*- coding:utf-8 -*- # Sociétés © 2015 Daniel Dumaresq # e-mail: [email protected] # Jabber: [email protected] # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License v3 as published by # the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License v3 # along with this program. If not, see <http://www.gnu.org/licenses/>. import pygame from pygame.locals import * import sys def set_allowed(): pygame.event.set_allowed([QUIT, MOUSEMOTION, MOUSEBUTTONDOWN, MOUSEBUTTONUP, KEYDOWN, KEYUP]) def handling(player_input): '''Handles every event. It returns the updates of the mouse position and of the state of the mouse (did it click? is the mouse pressed?).''' for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == MOUSEMOTION: player_input['mouse'] = event.pos elif event.type == MOUSEBUTTONDOWN: if event.button == 1: player_input['left clicked'] = True player_input['left mouse down'] = True if event.button == 3: player_input['right clicked']= True player_input['right mouse down'] = True elif event.type == MOUSEBUTTONUP: if event.button == 1: player_input['left mouse down'] = False if event.button == 3: player_input['right mouse down'] = False mousex, mousey = event.pos elif event.type == KEYDOWN: if event.key == K_RIGHT: pass elif event.key == K_LEFT: pass elif event.key == K_DOWN: pass elif event.key == K_UP: pass elif event.key == 304: player_input['shift'] = True elif event.type == KEYUP: if event.key == K_t: player_input['key up'] = 't' elif event.key == K_a: player_input['key up'] = 'a' elif event.key == K_c: player_input['key up'] = 'c' elif event.key == K_e: player_input['key up'] = 'e' elif event.key == K_h: player_input['key up'] = 'h' elif event.key == K_i: player_input['key up'] = 'i' elif event.key == K_p: player_input['key up'] = 'p' elif event.key == K_m: player_input['key up'] = 'm' elif event.key == K_s: player_input['key up'] = 's' elif event.key == K_w: player_input['key up'] = 'w' elif event.key == K_v: player_input['key up'] = 'v' elif event.key == K_z: player_input['key up'] = 'z' # this is for tests elif event.key == 42: # K_0 bépo player_input['key up'] = 0 elif event.key == 34: # K_1 bépo player_input['key up'] = 1 elif event.key == 171: # K_2 bépo player_input['key up'] = 2 elif event.key == 187: # K_3 bépo player_input['key up'] = 3 elif event.key == 13: # Enter bépo player_input['key up'] = 'Enter' elif event.key == 304: # Shift player_input['shift'] = False elif event.key == K_RIGHT: player_input['arrow key up'] = 'right' elif event.key == K_LEFT: player_input['arrow key up'] = 'left' elif event.key == K_DOWN: player_input['arrow key up'] = 'down' elif event.key == K_UP: player_input['arrow key up'] = 'up' else: print(event.key) return player_input
UTF-8
Python
false
false
2,014
19,559,281,092,753
0b176a94381a7ae5ec445f84811659a0416784f8
ec8dfffd95211927efcde58d6e6737193b8da9a9
/some-game/somegame.py
bed6547e00c07d2d1d81e019b28ea4062766d5ce
[]
no_license
laurieboyes/python-fiddles
https://github.com/laurieboyes/python-fiddles
9c4444adf388a9cf4293af4b2f7d2bab2a31843c
51ab4e3662738ad831b993caa063366f3c9854a3
refs/heads/master
2020-12-26T01:28:24.299354
2014-02-06T20:06:55
2014-02-06T20:06:55
null
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
import sys import pygame class SomeGame: def __init__(self, width=640, height=480): pygame.init() self.width = width self.height = height self.screen = pygame.display.set_mode((self.width, self.height)) def main_loop(self): while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() rect = pygame.Rect(100, 100, 100, 100) pygame.draw.rect(self.screen, (255, 0, 0), rect, 1) pygame.display.update()
UTF-8
Python
false
false
2,014
17,317,308,152,122
2c4a8ae5c7ede29cc483c6559987a0f3ac962c9b
09c3672799a8ef9bac74947e6a08b3db03626eed
/tags/templates/V2/setup.py
0d2f03142f289a5a749a367473482a59163e976e
[]
no_license
dragonskies/fix-fixer
https://github.com/dragonskies/fix-fixer
fc18d44d260a3cd9d6a96b6d4722b20da957f558
a2308c5a8491ab941b0b6ccc101f493826a65512
refs/heads/master
2021-01-10T20:58:17.008715
2012-03-01T20:15:09
2012-03-01T20:15:09
32,467,942
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
from distutils.core import setup import py2exe import os import sys import shutil manifest_template = ''' <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <assemblyIdentity version="5.0.0.0" processorArchitecture="x86" name="%(prog)s" type="win32" /> <description>%(prog)s Program</description> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly> ''' def remove_executables(): print "\n*** remove old executables ***" success = True executables = ['fixfixer_main.exe', 'fixfixer_gui.exe'] os.chdir('dist') for exe in executables: if os.path.isfile(exe): try: print "removing " + os.path.abspath(exe) os.remove(exe) except Exception: print "The file " + exe + " could not be removed. Is it in use, or is the path read-only?" success = False os.chdir('..') return success def update_dependencies(): print "\n*** update dependencies ***" dependencies = ['fix-fixer.ico', 'home.png', 'prev.png', 'next.png', 'help.html', 'fix_screenshot.jpg', 'Fields.xml'] try: shutil.copyfile('msvcp90.dll', os.path.join('dist', 'msvcp90.dll')) shutil.copyfile('msvcr90.dll', os.path.join('dist', 'msvcr90.dll')) except: pass dist_resources = os.path.join('dist', 'resources') if not os.path.isdir(dist_resources): os.chdir('dist') os.mkdir('resources') os.chdir('..') os.chdir(dist_resources) for file in dependencies: if os.path.isfile(file): try: print "removing " + os.path.abspath(file) os.remove(file) except Exception: print "The file " + file + " could not be removed. Is it in use, or is the path read-only?" return False os.chdir('..') os.chdir('..') for file in dependencies: if os.path.isfile(os.path.join('resources', file)): try: print "copying " + os.path.abspath(os.path.join('resources',file)) shutil.copyfile(os.path.join('resources', file), os.path.join(dist_resources, file)) except Exception: print "The file " + file + " could not be copied. Is the write path read-only?" return False else: print "The file " + file + " could not be found. Has it been removed?" return False return True def post_install(): print "\n*** post-installation ***" os.chdir('dist') print "renaming " + 'fixfixer_main.exe' + " -> " + 'fixfixer_gui.exe' os.rename( 'fixfixer_main.exe', 'fixfixer_gui.exe') os.chdir('..') if remove_executables() and update_dependencies(): print "\n*** compile binaries ***" icopath = os.path.join('resources', 'fix-fixer.ico') setup( name = "Fix Message Fixer", version = "2.0", license = "GPL", description = "An easy to use FIX message creator/editor for testing messaging systems.", options = {"py2exe":{"dll_excludes":["msvcr71.dll", "msvcp90.dll"], "bundle_files":1, "optimize":2, "compressed":True, "excludes":['_ssl', # Exclude _ssl 'pyreadline', 'difflib', 'doctest', 'optparse', 'pickle', 'calendar'],}}, zipfile = None, author = "Sean Davis, Timothy Davis", copyright = "Timothy Davis 2012", windows=[ { "script": 'fixfixer_main.py', "icon_resources":[(0, icopath), (1, icopath)], # "other_resources" : [(24, 1, # manifest_template % dict(prog="Fix Message Fixer"))], } ], data_files=["msvcp90.dll"], ) post_install()
UTF-8
Python
false
false
2,012
14,731,737,845,355
e3d15fb9562717206ad1a0cc02255f99256b9f53
cb244c163a2307b4496b45c9f42dfd9151e0513b
/splice_upstream.py
71752f61ebaeb9bfe3e454c33557fe5c93693056
[]
no_license
matidae/scripts-ngs
https://github.com/matidae/scripts-ngs
c0a6e06e569142f3f6594e27f123028e8bebc221
5ef8d8c2a07cf93d76b49b4dedb77adeca9c424b
refs/heads/master
2020-05-18T00:23:55.187958
2013-05-07T17:05:51
2013-05-07T17:05:51
null
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
import sys from Bio import SeqIO #Corta seq nlen bp de largo upstream (500 por default) a partir de un GFF #Params: lista.genes, file.gff, [len.margen] lista = open(sys.argv[1],'r').readlines() index = SeqIO.index(sys.argv[2], 'fasta') try: nlen = int(sys.argv[3]) except: nlen = 500 for i in lista: chr = i.split()[0] name = i.split()[8].split(";")[0].replace("ID=","") strand = i.split()[6] start = int(i.split()[3]) end = int(i.split()[4]) if strand == "+": seq = index[chr].seq[start-nlen:end] else: seqaux = index[chr].seq[start:end+nlen] seq = seqaux.reverse_complement() if len(seq) < nlen: seq = index[chr].seq[:end] if strand == "+" else index[chr].seq[start:] print ">" + name n=60 for i in xrange(0, len(seq), n): print seq[i:i+n]
UTF-8
Python
false
false
2,013
1,958,505,130,804
f843babe15dea06b983c1bb6ad415a9a816be5f7
669476007534600a2fb3457e343f9866aa682885
/setup.py
7c0d38276c9457ed29350ccba443138bedb76a6f
[ "MIT" ]
permissive
putaodoudou/robotframework-imaging
https://github.com/putaodoudou/robotframework-imaging
dec51046c07f94ba74e8603755a05e5cddc24014
b3d127463c35de43f1242e400c24b4f9e08e9ee2
refs/heads/master
2021-05-28T07:09:13.400839
2014-09-24T12:59:11
2014-09-24T12:59:11
null
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
#!/usr/bin/env python from distutils.core import setup CLASSIFIERS = """ Programming Language :: Python Topic :: Software Development :: Testing """[1:-1] from os.path import join, dirname long_description = open(join(dirname(__file__), 'README.md',)).read() setup( name='robotframework-Imaging', version="0.0.1", description='Robotframework utility keyworks for image comparing', long_description=long_description, author='Aniello Barletta', author_email='[email protected]', url='https://github.com/shadeimi/robotframework-imaging', license='Beerware', keywords='robotframework testing testautomation web css webtest', platforms='any', zip_safe=False, classifiers=CLASSIFIERS.splitlines(), package_dir={'': 'src'}, install_requires=['robotframework', 'robotframework-selenium2library', 'Pillow', 'cssutils'], packages=['Imaging'] )
UTF-8
Python
false
false
2,014
10,642,928,977,068
604f28214440613cfd727c9f4229204d14bd5143
6045d53cbded62edd89a4acbb089a2f1115f210b
/mer567/userInteraction/interaction.py
f2932d418af728811402102f89b7c9bc2b79e4f8
[]
no_license
mrotmensch/assignment11
https://github.com/mrotmensch/assignment11
1688e0a2689dae5d003409ce6993b20c09bb255c
693572f333ce58466632c3020cf6520c355a2ad9
refs/heads/master
2021-01-21T07:17:09.360899
2014-12-07T03:23:46
2014-12-07T03:23:46
null
0
0
null
null
null
null
null
null
null
null
null
null
null
null
null
import re import sys import fnmatch import numpy as np class string_not_compatible(Exception): pass class wrong_denominations(Exception): pass def user_input(prompt,user_end,str_parser): """ Function clled to except user input. does not terminate until input is valid Args: prompt: string. the prompt displayed to the user user_end: string. command with which user can end program str_parser: function. the function with which to parse and verify input. Returns: input_parsed: the parsed and checked version of user input """ check = False while check == False: try: user_input = raw_input(prompt) input_parsed = str_parser(user_input) check = True except (wrong_denominations, string_not_compatible) as s: print s except KeyboardInterrupt as k: print " \n You chose to terminate the program ... Goodbye now!" sys.exit() return input_parsed def parse_input_positions(user_input): """ Function attempts to parse user input. If input cannot be parsed, raises appropriate error. Args: user_input: string. user input for prompt. Returns: list of positions to be used in simulations. each entry is list is int. """ input_no_space = user_input.replace( " ", "") #check for empyt string if input_no_space == "": raise string_not_compatible("Please make sure your input follows the example : '[1, 10, 100, 1000]' ") #check for proper list notation if input_no_space[0] != "[" or input_no_space[-1] != "]": raise string_not_compatible("Please make sure your input follows the example : '[1, 10, 100, 1000]' ") # split up string by expected delim split_str = input_no_space[1:-1].split("," ) #if any element in the list is empty, raise exception if not any(split_str): raise string_not_compatible("Please make sure your input follows the example : '[1, 10, 100, 1000]' ") # check that every entry is an int try: formatted_input = [int(x) for x in split_str] except: raise string_not_compatible("Please make sure your input follows the example : '[1, 10, 100, 1000]' ") #can only purchase it in $1, $10, $100, and $1000 denominations. money_on_each_stock = 1000.0/np.array(formatted_input) for money in money_on_each_stock: if (money%1 != 0) or money == 0 : raise wrong_denominations("smallest denomination available is $1") return formatted_input def parse_input_number(user_input): """ Function attempts to parse user input. If input cannot be parsed, raises appropriate error. Args: user_input: string. user input for prompt. Returns: int. the number of trials for which the simulation will run. """ input_no_space = user_input.replace( " ", "") # tranform into integer number of trials try: formatted_number = int(input_no_space) except: raise string_not_compatible("please enter a valid number of trials. Ex: 5") return formatted_number
UTF-8
Python
false
false
2,014