Esempio n. 1
0
 def getrandom(self):
     if not 'sides' in request.GET or not 'num' in request.GET:
         abort(500)
     sides = (int)(request.GET['sides'])
     num = (int)(request.GET['num'])
     r = RDO()
     return json.dumps(r.randrange(1,sides,1,num))
Esempio n. 2
0
class RandomPasswd:
    """This class can be used to generate secure passwords.

    To use, do something like the following:

    >>> from randompasswd import RandomPasswd
    >>> p = RandomPasswd()
    >>> print p.passwd()
    """

    # A list of characters that will be used to generate a password.
    lower = [
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
        'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
    ]

    upper = [
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
        'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
    ]

    number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

    punctuation = [
        '`', '!', '"', '$', '%', '^', '&', '*', '(', ')', '\'', '-', '_', '=',
        '+', '[', '{', ']', '}', ';', ':', '?', '@', '#', '~', '\\', '|', ',',
        '<', '.', '>', '/'
    ]

    # Creating the characters variable that will, according to the security
    # level contain a list of characters from the above lists.
    characters = list()

    # Our quota at random.org.
    quota = None

    # Start the random.org api class.
    rand = RandomDotOrg()

    def set_security(self, strength):
        """Takes the given security strength and generates a mixed list for `characters`."""

        if strength < 0 or strength > 4:
            raise ValueError("Please enter a strength between 0 and 4.")

        if strength >= 0:
            self.characters = self.lower

        if strength >= 1:
            self.characters += self.upper

        if strength >= 2:
            self.characters += self.number

        if strength >= 3:
            self.characters += self.punctuation

    def get_random_characters(self, length):
        """Retrives the random string of numbers for our password."""

        # Use the random.org API to get our random numbers.
        self.quota = self.rand.get_quota()

        if self.quota > 0:
            numbers = self.rand.randrange(0,
                                          len(self.characters),
                                          ammount=int(length))

        else:
            raise ValueError("Out of random.org bits...")

        random_characters = list()

        # Shuffle the list of characters we are using.
        self.rand.shuffle(self.characters)

        for i in numbers:
            random_characters.append(self.characters[i])

        return random_characters

    def passwd(self, length=14, strength=4, amount=1):
        """Generates a strong password with a default length of 14.

        `length`   the length of the password(s).

        `strength` the strength of the password(s), 0 is low
                   4 is very high.

        `amount`   the number of passwords you would like to make,
                   when more than one is made, this function
                   returns a list of strings.
        """

        if amount < 1:
            raise ValueError("`amount` needs to be a positive integer.")

        total_chars = length * amount

        # Avoid requesting too large an amount of random intgers.
        if total_chars > 10000:

            if length > amount:
                raise ValueError("Please request a smaller password length.")
            else:
                raise ValueError(
                    "Please generate a smaller number of passwords.")

        self.set_security(strength)

        random_characters = self.get_random_characters(total_chars)

        count = 0
        password = list()

        # Splice up the list of random_characters into seperate passwords.
        while count < total_chars:

            password.append(''.join(random_characters[count:count + length]))

            count += length

        return password
Esempio n. 3
0
class Repositories(db.Model):
    __tablename__ = 'repositories'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(300), unique=True)
    full_name = db.Column(db.String(300), unique=True)
    html_url = db.Column(db.String(300), unique=True)
    description = db.Column(db.String(3000), unique=True)

    def __init__(self, name, full_name, html_url, description):
        self.name = name
        self.full_name = full_name
        self.html_url = html_url
        self.description = description

true_random = RandomDotOrg('randomrepo.com')
if true_random:
    random_page = str(true_random.randrange(1, 4000))
else:
    random_page = str(random.randrange(1, 4000))

random_repo = requests.get('https://api.github.com/search/repositories?q=+stars:0..10+?since=' + random_page).json()
repos = random_repo['items']

for i in repos:
    name = i['name']
    full_name = i['full_name']
    html_url = i['html_url']
    description = i['description']
    break
Esempio n. 4
0
"""
from randomdotorg import RandomDotOrg
import logging

#
# Configure logging-format and level
#
logging.basicConfig(
    format = '%(levelname)s:%(name)s:%(funcName)s:%(message)s',
    level = logging.DEBUG)


#
# Instanciate module variables
#
RANDOMIZER = RandomDotOrg()
LOGGER = logging.getLogger(__name__)
DEFAULT_SORTING = lambda x, y: x >= y

#
# Sort values
#
def sort(values, sorting=DEFAULT_SORTING):
    """
      Define sort function
      values: list of values to be sorted randomly
      return: sorted list of values
    """
    randomized_values = randomize(values)
    while not is_sorted(randomized_values, sorting):
        randomized_values = randomize(randomized_values)
Esempio n. 5
0
from plone import api
from selenium import webdriver
from pyvirtualdisplay import Display

import smtplib
from email.mime.text import MIMEText
from smtplib import SMTPRecipientsRefused

import signal, os

# yeah i know, i know - [email protected]
issue_tracker = xmlrpclib.ServerProxy(
    'http://*****:*****@automaton.isaw.nyu.edu:8082/help/', allow_none=True)

random = RandomDotOrg()


def SIGCHLDReaper(signum, frame):
    print "%s %s" % (signum, frame)
    os.waitpid(-1, os.WNOHANG)


signal.signal(signal.SIGCHLD, SIGCHLDReaper)


def checkEmailAddress(value):
    portal = getUtility(ISiteRoot)
    reg_tool = getToolByName(portal, 'portal_registration')
    if value and reg_tool.isValidEmail(value):
        pass
Esempio n. 6
0
 def random_org(self, begin=begin, end=end, floating=False):
     return RandomDotOrg().randint(begin, end)
Esempio n. 7
0
from randomdotorg import RandomDotOrg

r = RandomDotOrg('die roll [email protected]')

if r.get_quota() > 0:
    print r.randint(1, 6)
else:
    print 'Somehow you\'ve exceeded 10,0000 requests today'
#!/usr/bin/python
# -*- coding: utf-8 -*-

# SOMEONE PLEASE FORK THIS! I CANT STAND LOOKING AT IT! SO. BADLY. CODED.
# *crying*

import os
import webbrowser
import json
import urllib2
from urllib2 import Request, urlopen, URLError
# from bs4 import BeautifulSoup
from randomdotorg import RandomDotOrg
import textwrap

random = RandomDotOrg('RandomAdventure')


class bcolors:
    OKBLUE = '\033[94m'
    RED = '\033[31m'
    ENDCOLOR = '\033[0m'
    BOLD = '\033[1m'
    ATBG = '\033[40m'
    ATFG = '\033[33m'
    DIM = '\033[2m'
    UNDERLINE = '\033[4m'


def randomAdventure(
):  # Funktion der finder et tilfældigt afsnit og dets info vha. Adventure Time API