Ejemplo n.º 1
0
def read_text():
    # create a File object/instance by calling its init function
    text_file = open(os.path.expanduser(use_path))
    print ( ("Text file: {}".format(text_file)) if (python_version.current_version() == 3) else ("Text file: %s") % (text_file) )

    contents = text_file.read()
    print ( ("Contents of file: {}".format(contents)) if (python_version.current_version() == 3) else ("Contents of file: %s") % (contents) )

    text_file.close()
    check_profanity(contents)
Ejemplo n.º 2
0
def check_profanity(some_text):
    print("Filtering profanities from text...")
    if (python_version.current_version() == 3):
        url = "http://www.purgomalum.com/service/json?"
        data = {
            'text': some_text,
            'add': 'bloody,bomb,galaxy note 7',
            'fill_text': '****'
        }
        encodeddata = urllib.parse.urlencode(data).encode('UTF-8')
        # data=u"{}&add=bloody,bomb,galaxy note 7&fill_text=****".format(some_text)
        # encodeddata = data.encode('utf-8')
        # req = urllib.request.Request(url, encodeddata) # POST (not desired!)
        req = urllib.request.Request(url + encodeddata) # GET
        response = urllib.request.urlopen(req)
    else:
        response = urllib.urlopen("http://www.purgomalum.com/service/json?text=" + some_text + "&add=bloody,bomb,galaxy note 7" + "&fill_text=****")
    data = json.loads(response.read().decode('utf8'))
    print ( ("Filtered text: {}".format(data["result"])) if (python_version.current_version() == 3) else ("Filtered text: %s") % () )
    response.close()
Ejemplo n.º 3
0
def rename_files():
    # get filenames from folder
    current_directory = os.getcwd()
    samples_folder_name = "temp"
    samples_absolute_path = current_directory + ''.join(
        ['/', samples_folder_name, '/'])

    print(("Sample path {}".format(samples_absolute_path)) if (
        python_version.current_version() == 3) else ("Sample path %s") %
          (samples_absolute_path))

    file_list = os.listdir(''.join(['./', samples_folder_name]))
    print(("Subdirectory contents: {}".format(file_list)) if (
        python_version.current_version() == 3
    ) else ("Subdirectory contents: %s") % (file_list))

    # rename each file with new random suffix
    for index, filename in enumerate(file_list, 0):
        print(("Before - Index: {}, Filename: {}".format(index, filename)) if (
            python_version.current_version() == 3
        ) else ("Before - Index: %s, Filename: %s") % (index, filename))

    random_filename_suffix = str(randint(0, 99))

    # generate new random file suffix until it does not match any numbers already in the filename
    while file_handler_util.random_number_already_exists_in_filename(
            filename, random_filename_suffix):
        random_filename_suffix = str(randint(0, 99))

    new_filename_random_no = file_handler_util.remove_numbers_from_filename_and_append_rand_int(
        filename, random_filename_suffix)
    new_filename = file_handler_util.replace_non_numbers_with_rand_chars(
        new_filename_random_no)
    updated_file_list = rename_filename(samples_folder_name,
                                        samples_absolute_path, filename,
                                        new_filename)
    print(("After - Index: {}, Filename: {}".
           format(index, updated_file_list[index])) if (
               python_version.current_version() == 3
           ) else ("After - Index: %s, Filename: %s") %
          (index, updated_file_list[index]))
Ejemplo n.º 4
0
def random_number_already_exists_in_filename(filename, random_filename_suffix):
    randfile_ints_found = re.findall(
        '\d+', filename)  # array of numbers found in filename
    # suffix_matches_found = py_(randfile_ints_found).map(lambda x: x == random_filename_suffix).each(print).value()
    suffix_matches_found = py_(randfile_ints_found).map(
        lambda x: x == random_filename_suffix).each().value()
    print(("Numbers in filename matching proposed new random no: {}".format(
        suffix_matches_found)) if (python_version.current_version() == 3) else
          ("Numbers in filename matching proposed new random no: %s") %
          (suffix_matches_found))

    assert (len(suffix_matches_found) >
            0), 'Filename does not contain any numbers!'
    return True if any(element for element in suffix_matches_found) else False
Ejemplo n.º 5
0
def get_main_path():
    app_path = sys.path[0]  # sys.path[0] is current path in subdirectory
    split_on_char = "/"
    return split_on_char.join(app_path.split(split_on_char)[:-1])


main_path = get_main_path()
print(main_path)
site.addsitedir(main_path + '/helpers')
site.addsitedir(main_path + '/util')
from helpers import reusable  # __init__.py required in the helpers subdirectory
from util import python_version

print(("Imported subfolder: {}/helpers".format(sys.path[0])) if (
    python_version.current_version() == 3) else ("Imported subfolder: %s") %
      (main_path + '/helpers'))
print(("Imported subfolder: {}/util".format(sys.path[0])) if (
    python_version.current_version() == 3) else ("Imported subfolder: %s") %
      (sys.path[0] + '/util'))

# Settings
REPLAY_QTY = 100
SHAPE = reusable.shape["rectangle"]
# Example ROTATION_FACTOR values:
# 0.5: rotate around 18 times every 20 degrees
# 1: rotate around 36 times every 10 degrees
# 2: rotate around 72 times every 5 degrees
ROTATION_FACTOR = 0.75

ROTATIONS = int(36 * ROTATION_FACTOR)
Ejemplo n.º 6
0
import site


def get_main_path():
    app_path = sys.path[0]  # sys.path[0] is current path in subdirectory
    split_on_char = "/"
    return split_on_char.join(app_path.split(split_on_char)[:-1])


main_path = get_main_path()
site.addsitedir(main_path)
site.addsitedir(main_path + '/util')
from util import python_version

print(("Importing main folder: {}".format(main_path)) if (
    python_version.current_version() == 3) else ("Importing main folder: %s") %
      (main_path))

import settings

from twilio.rest import TwilioRestClient

account_sid = settings.LIVE_TWILIO_ACCOUNT_SID  # Your Account SID from www.twilio.com/console
auth_token = settings.LIVE_TWILIO_AUTH_TOKEN  # Your Auth Token from www.twilio.com/console

client = TwilioRestClient(account=account_sid, token=auth_token)

message = client.messages.create(
    body="Hello from Python",
    to=settings.RECIPIENT_PHONE_NUMBER,  # Replace with your phone number
    from_=settings.TWILIO_PHONE_NUMBER)  # Replace with your Twilio number
Ejemplo n.º 7
0
import os
import time
import webbrowser
import site

# IMPORT CUSTOM FILES

site.addsitedir(sys.path[0] + '/helpers')
from helpers import reusable  # __init__.py required in the helpers subdirectory

site.addsitedir(sys.path[0] + '/util')
from util import python_version

# SHOW INFO
print(("System path: {}".format(sys.path)) if (
    python_version.current_version() == 3) else ("System path: %s") %
      (sys.path))
print(("Env keys: {}".format(os.environ.keys())) if (
    python_version.current_version() == 3) else ("Env keys: %s") %
      (os.environ.keys()))
print(("Imported subfolder: {}/helpers".format(sys.path[0])) if (
    python_version.current_version() == 3) else ("Importing subfolder: %s") %
      (sys.path[0] + '/helpers'))

again = "y"
break_limit = 3
break_count = 0
remaining = break_limit

while again == "y" and break_count < break_limit:
    time.sleep(3)  # seconds
Ejemplo n.º 8
0
 def show_info(self):
     print(("Movie {} info: {}, {}".
            format(self.title, self.cinema_name, self.cinema_location)) if (
                python_version.current_version() == 3
            ) else ("Movie %s info: %s, %s") %
           (self.title, self.cinema_name, self.cinema_location))
Ejemplo n.º 9
0
elif "/".join(os.getcwd().split("/")[-1:]) == "profanity_detector": # current folder name
    use_path = os.getcwd() + "/text"

# IMPORT CUSTOM FILES

import site
def get_main_path():
    app_path = sys.path[0] # sys.path[0] is current path in subdirectory
    split_on_char = "/"
    return split_on_char.join(app_path.split(split_on_char)[:-1])
main_path = get_main_path()
print (main_path)
site.addsitedir(main_path+'/util')
from util import python_version

if (python_version.current_version() == 3):
    import urllib.request
else:
    import urllib

print ( ("Imported subfolder: {}/util".format(sys.path[0])) if (python_version.current_version() == 3) else ("Imported subfolder: %s") % (sys.path[0]+'/util') )

print ( ("Use path: {}".format(use_path)) if (python_version.current_version() == 3) else ("Use path; %s") % (use_path) )

def read_text():
    # create a File object/instance by calling its init function
    text_file = open(os.path.expanduser(use_path))
    print ( ("Text file: {}".format(text_file)) if (python_version.current_version() == 3) else ("Text file: %s") % (text_file) )

    contents = text_file.read()
    print ( ("Contents of file: {}".format(contents)) if (python_version.current_version() == 3) else ("Contents of file: %s") % (contents) )
Ejemplo n.º 10
0
    split_on_char = "/"
    return split_on_char.join(app_path.split(split_on_char)[:-1])


main_path = get_main_path()
print(main_path)
site.addsitedir(main_path + '/util')
from util import python_version

import fresh_tomatoes
import media
import cinema

ritz = cinema.Cinema("Ritz", "Sydney")
print(("Cinema location of Ritz is: {}".format(ritz.cinema_location)) if (
    python_version.current_version() == 3
) else ("Cinema location of Ritz is: %s") % (ritz.cinema_location))

rambo = media.Movie(
    "Baroque Theatre", "Melbourne", "Rambo", "Action movie",
    "http://www.eujacksonville.com/pages/01-31-08/Rambo%20movie%20review.jpg",
    "https://youtu.be/aL39jJN9hHM?t=27s")

print(("Rambo shown at: {}".format(rambo.show_info())) if (
    python_version.current_version() == 3) else ("Rambo shown at: %s") %
      (rambo.show_info()))
print(("Rambo description: {}".format(rambo.description)) if (
    python_version.current_version() == 3) else ("Rambo description: %s") %
      (rambo.description))
print(("Movie valid ratings: {}".format(media.Movie.VALID_RATINGS)) if (
    python_version.current_version() == 3) else ("Movie valid ratings: %s") %