Example #1
0
    def list_directory(self, path):
        try:
            list = os.listdir(path)
        except os.error:
            self.send_error(404, "No permission to list directory")
            return None
        list.sort(key=lambda a: a.lower())
        f = StringIO()
        displaypath = cgi.escape(urllib.unquote(self.path))
        f.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">')
        f.write("<html>\n<title>Diabetic retinopathy screening</title>\n")
        f.write("<body>\n<a href=\"https://github.com/nomikxyz/retinopathy-server\"><img style=\"position: absolute; top: 0; right: 0; border: 0;\" src=\"https://camo.githubusercontent.com/365986a132ccd6a44c23a9169022c0b5c890c387/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f7265645f6161303030302e706e67\" alt=\"Fork me on GitHub\" data-canonical-src=\"https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png\"></a><h2>Diabetic retinopathy screening</h2>\n")
        f.write("<hr>\n")
        f.write("<form accept-charset=utf-8 ENCTYPE=\"multipart/form-data\" method=\"post\">")
        f.write("<input name=\"file\" type=\"file\"/>")
        f.write("<input type=\"submit\" value=\"upload\"/></form>\n")
        f.write("</body></html>")
        length = f.tell()
        f.seek(0)
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.send_header("Content-Length", str(length))
        self.end_headers()
	cleanup.clean()
	return f
Example #2
0
    def test_increasealiaskarmawithcombine(self):
        cleanup.clean()

        # Process alias instead via process()
        text = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'patata++',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(text)

        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 1)

        stampy.plugin.alias.createalias('patata', 'creilla')

        # Process alias instead via process()
        text = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'patata++',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(text)

        # Karma has been given to patata, but alias gave it to creilla and also it was combined with previous karma
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 0)
        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 2)
Example #3
0
 def start(self, widget, data):
     arr = []
     def dofor(model, path, theiter, data=None):
         arr.append(self.data[model.get_value(theiter, 0)])
     data['treemodel'].foreach(dofor)
     self.window.hide()
     while gtk.events_pending():
         gtk.main_iteration(block=False)
     ModLoader(arr).prepMods().load()
     runGame()
     clean()
     gtk.main_quit()
Example #4
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_info(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'/info',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)
Example #5
0
    def test_increasealiaskarmawithcombine(self):
        cleanup.clean()

        # Process alias instead via process()
        text = [{u'message': {u'date': 1478361249, u'text': u'patata++', u'from': {u'username': u'iranzo', u'first_name': u'Pablo', u'last_name': u'Iranzo G\xf3mez', u'id': 5812695}, u'message_id': 108, u'chat': {u'all_members_are_administrators': True, u'type': u'group', u'id': -158164217, u'title': u'BOTdevel'}}, u'update_id': 837253571}]
        stampy.stampy.process(text)

        self.assertEqual(plugin.karma.getkarma('patata'), 1)

        plugin.alias.createalias('patata', 'creilla')

        # Process alias instead via process()
        text = [{u'message': {u'date': 1478361249, u'text': u'patata++', u'from': {u'username': u'iranzo', u'first_name': u'Pablo', u'last_name': u'Iranzo G\xf3mez', u'id': 5812695}, u'message_id': 108, u'chat': {u'all_members_are_administrators': True, u'type': u'group', u'id': -158164217, u'title': u'BOTdevel'}}, u'update_id': 837253571}]
        stampy.stampy.process(text)

        # Karma has been given to patata, but alias gave it to creilla and also it was combined with previous karma
        self.assertEqual(plugin.karma.getkarma('patata'), 0)
        self.assertEqual(plugin.karma.getkarma('creilla'), 2)
Example #6
0
def tokens(file_name):
    """
    Input: file name of the source text
    
    Output: list of tokens from a text
    """
    clean_text = clean(file_name)
    split_words = clean_text.split()
    print(len(split_words))
    return split_words
Example #7
0
 def update(self, iterable):
     """Update this histogram with the items in the given iterable"""
     for item in iterable:
         item = cleanup.clean(item)
         self.tokens += 1
         if item not in self:
             self[item] = 1
             self.types += 1
         else:
             self[item] += 1
Example #8
0
def prepare_data(paragraphs):
    sentences = []
    for paragraph in paragraphs:
        sentences = sentences + prepare.prepare(cleanup.clean(paragraph))

    model = {}
    for sentence in sentences:
        model = make_pairs(tokenize.tokenize(sentence), model)

    return model
Example #9
0
    def test_increasealiaskarma(self):
        cleanup.clean()

        stampy.plugin.karma.putkarma('patata', 1)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 1)

        # Alias doesn't get increased as the 'aliases' modifications are in
        # process, not in the individual functions
        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 0)

        # Reset patata status for the next test
        stampy.plugin.karma.putkarma('patata', 0)

        # Create alias
        stampy.plugin.alias.createalias(word='patata', value='creilla')

        # Process alias instead via process()
        text = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'patata++',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(text)

        # Karma has been given to patata, but alias gave it to creilla
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 0)
        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 1)
class TestStampy(TestCase):
    cleanup.clean()

    def test_createautok(self):
        self.assertEqual(
            stampy.plugin.autokarma.createautok('transcod', 'chupito'), True)

    def test_getautok(self):
        self.assertEqual(stampy.plugin.autokarma.getautok('transcod'),
                         ['chupito'])

    def test_removeautok(self):
        self.assertEqual(
            stampy.plugin.autokarma.deleteautok('transcod', 'chupito'), True)
Example #11
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_putkarma(self):
        stampy.plugin.karma.putkarma('patata', 0)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 0)

    def test_updatekarmaplus(self):
        stampy.plugin.karma.updatekarma('patata', 2)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 2)

    def test_updatekarmarem(self):
        stampy.plugin.karma.updatekarma('patata', -1)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 1)
Example #12
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_00stats(self):
        # test that no empty [] groups are added
        stampy.plugin.stats.updatestats(type='chat',
                                        id=-1,
                                        name="Test",
                                        date=False,
                                        memberid=[])
        self.assertEqual(stampy.plugin.stats.getstats(id=-1, type='chat'),
                         ('chat', -1, u"Test", u'False', 1, []))

    def test_01pingchat(self):
        stampy.plugin.stats.pingchat(-1)
        (type, id, name, date, count,
         memberid) = stampy.plugin.stats.getstats(type='chat', id=-1)
        self.assertEqual(stampy.plugin.stats.getstats(id=-1, type='chat'),
                         ('chat', -1, u"Test", date, count, []))
Example #13
0
 def update(self, iterable):
     """Update this histogram with the items in the given iterable"""
     for item in iterable:
         item = cleanup.clean(item)
         self.tokens += 1
         if len(self) > 0:
             contained = False
             for word in self:
                 if word[0] == item:
                     tup = (word[0], word[1] + 1)
                     self.remove(word)
                     self.append(tup)
                     contained = True
                     break
             if contained == False:
                 word = (item, 1)
                 self.append(word)
                 self.types += 1
         elif len(self) == 0:
             word = (item, 1)
             self.append(word)
             self.types += 1
Example #14
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_welcome(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4829,
                                 "from": {"id": 5812695, "first_name": "Pablo",
                                          "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel",
                                          "type": "group",
                                          "all_members_are_administrators": true},
                                 "date": 1497476575,
                                 "new_chat_participant": {"id": 279488169,
                                                          "first_name": "stampytest_bot",
                                                          "username": "******"},
                                 "new_chat_member": {"id": 279488169,
                                                     "first_name": "stampytest_bot",
                                                     "username": "******"},
                                 "new_chat_members": [
                                     {"id": 279488169, "first_name": "stampytest_bot",
                                      "username": "******"}]}}]
        stampy.stampy.process(messages)
Example #15
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_putkarma(self):
        stampy.plugin.karma.putkarma('patata', 0)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 0)

    def test_updatekarmaplus(self):
        stampy.plugin.karma.updatekarma('patata', 2)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 2)

    def test_updatekarmarem(self):
        stampy.plugin.karma.updatekarma('patata', -1)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 1)

    def test_rank(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'rank',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)

    def test_skarma(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'skarma cebolla=20',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)

    def test_srank(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'srank iranzo',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)

    def test_skarmapurge(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'skarma purge',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)
Example #16
0
    total_words = gram.tokens

    # create list of words and counts
    words, counts = zip(*histogram)

    # create list of weights from counts
    weights = [count / total_words for count in counts]

    # generate a random word based on weights
    random_word = ''
    while random_word == '':
        random_index = random.randrange(len(words))
        if random.random() < weights[random_index]:
            random_word = words[random_index]

    # return random word
    return random_word


if __name__ == '__main__':
    import sys
    from tokenize import get_words
    from cleanup import clean
    from dictogram import Dictogram
    words = get_words(sys.argv[1])
    cleaned_words = clean(words)
    listogram = Dictogram(cleaned_words)
    random_weighted_word = get_random_word(listogram)

    # print random weighted word
    print(random_weighted_word)
Example #17
0
 def update(self):
     if self.updater.need_update():
         result = self.updater.update()
         cleanup.clean(cleanup.FOLDER_STRUCTURE)
         return result
Example #18
0
#!/usr/bin/env python
# coding=utf-8

from __future__ import print_function

import cleanup
cleanup.clean('core', 'libs')

import datetime
import os
import sys

import core
from core import logger, main_db
from core.auto_process import comics, games, movies, music, tv
from core.auto_process.common import ProcessResult
from core.user_scripts import external_script
from core.utils import char_replace, clean_dir, convert_to_ascii, extract_files, get_dirs, get_download_info, get_nzoid, plex_update, update_download_info_status

try:
    text_type = unicode
except NameError:
    text_type = str


# post-processing
def process(input_directory, input_name=None, status=0, client_agent='manual', download_id=None, input_category=None, failure_link=None):
    if core.SAFE_MODE and input_directory == core.NZB_DEFAULTDIR:
        logger.error(
            'The input directory:[{0}] is the Default Download Directory. Please configure category directories to prevent processing of other media.'.format(
                input_directory))
Example #19
0
 def test_owner(self):
     cleanup.clean()
     self.assertEqual(stampy.plugin.config.config('owner'), 'iranzo')
Example #20
0
 def test_remove_extra_spaces(self):
     self.assertEqual(cleanup.clean('This is foo.  This is bar.'),
                      'This is foo. This is bar.')
Example #21
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_createalias(self):
        stampy.plugin.alias.createalias('patata', 'creilla')
        self.assertEqual(stampy.plugin.alias.getalias('patata'), 'creilla')

    def test_getalias(self):
        self.assertEqual(stampy.plugin.alias.getalias('patata'), 'creilla')

    def test_aliaslist(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'/alias list',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)

    def test_aliasadd(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'/alias bacon=tocino',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)

    def test_aliasdel(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'/alias delete bacon',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)
Example #22
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_createalias(self):
        stampy.plugin.alias.createalias('patata', 'creilla')
        self.assertEqual(stampy.plugin.alias.getalias('patata'), 'creilla')

    def test_getalias(self):
        self.assertEqual(stampy.plugin.alias.getalias('patata'), 'creilla')

    def test_increasealiaskarma(self):
        cleanup.clean()

        stampy.plugin.karma.putkarma('patata', 1)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 1)

        # Alias doesn't get increased as the 'aliases' modifications are in
        # process, not in the individual functions
        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 0)

        # Reset patata status for the next test
        stampy.plugin.karma.putkarma('patata', 0)

        # Create alias
        stampy.plugin.alias.createalias(word='patata', value='creilla')

        # Process alias instead via process()
        text = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'patata++',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(text)

        # Karma has been given to patata, but alias gave it to creilla
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 0)
        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 1)

    def test_increasealiaskarmawithcombine(self):
        cleanup.clean()

        # Process alias instead via process()
        text = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'patata++',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(text)

        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 1)

        stampy.plugin.alias.createalias('patata', 'creilla')

        # Process alias instead via process()
        text = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'patata++',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(text)

        # Karma has been given to patata, but alias gave it to creilla and also it was combined with previous karma
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 0)
        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 2)

    def test_removealias(self):
        stampy.plugin.alias.deletealias('patata')

        # After alias has been removed, the words are no longer linked
        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 2)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 0)

        # Increase  karma again via process and revalidate
        text = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'patata++',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(text)

        self.assertEqual(stampy.plugin.karma.getkarma('creilla'), 2)
        self.assertEqual(stampy.plugin.karma.getkarma('patata'), 1)
Example #23
0
 def test_replace_ellipses(self):
     self.assertEqual(cleanup.clean('Where is baz...'), 'Where is baz…')
Example #24
0
def preprocess(dir, fn):
    """
    Data preprocessing function. Given input directory, image and mask data is
    copied into a new temporary working directory called "data_copy". Data from
    the input directory is copied to "data_copy" and processed.

    Parameters
    ----------
    dir : str
        String for the directory to perform training with.
    n : int
        The factor of augmented images to generate with Augmentor.

    Returns
    -------
    None : All processed images are saved into the data_copy directory.

    """

    # Insert condition to check whether the augmentation generates NaN data
    # If so, repeat the entire process again...
    nandetected = False

    while not nandetected:
        data_copy_dir = dir.strip('/')+'_WORKINGCOPY'

        training_data_dir = os.path.join(data_copy_dir, 'training_data')
        test_data_dir = os.path.join(data_copy_dir, 'test_data')

        # Clean up any old directories and create new directories
        cleanup.clean()

        os.makedirs(os.path.join(training_data_dir, 'images'))
        os.makedirs(os.path.join(training_data_dir, 'masks'))

        os.makedirs(os.path.join(test_data_dir, 'images'))
        os.makedirs(os.path.join(test_data_dir, 'masks'))

        # Make a working directory copy of data so we don't lose anything
        os.makedirs(os.path.join(data_copy_dir, 'images'))
        os.makedirs(os.path.join(data_copy_dir, 'masks'))
        copy_tree(os.path.join(dir, 'images'), os.path.join(data_copy_dir, 'images'))
        copy_tree(os.path.join(dir, 'masks'), os.path.join(data_copy_dir, 'masks'))

        print ('Performing basic rotation and flipping augmentation on data copy...')

        augmentation.basicaugment(data_copy_dir)

        print ('Done!')

        print ('Performing augmentation on data copy...')

        if fn>0:
            images_data = os.listdir(data_copy_dir+'/images/')
            n=fn*len(images_data)
            augmentation.augment(data_copy_dir,n)

            aug_images = glob.glob(data_copy_dir+'/images/images_original*')
            aug_masks = glob.glob(data_copy_dir+'/images/_groundtruth*')
            aug_images.sort(key=lambda x:x[-40:])
            aug_masks.sort(key=lambda x:x[-40:])

            for i, (image_file, mask_file) in enumerate(zip(aug_images, aug_masks)):
                shutil.move(image_file, image_file.replace('images_original_', ''))
                shutil.move(mask_file, mask_file.replace('_groundtruth_(1)_images_', '').replace('/images/', '/masks/'))

            print ('Augmented and saved with n='+str(n)+' samples!')

        print ('Randomly selecting/moving 70% training and 30% test data...')
        images_data = natsorted(os.listdir(data_copy_dir+'/images/'))
        masks_data = natsorted(os.listdir(data_copy_dir+'/masks/'))

        # Changed the sampling so they sample approximately the same distribution
        # Now sampling is 75:25
        test_images_data = images_data[::4]
        test_masks_data = [f.replace('/images/', '/masks/') for f in test_images_data]
        training_images_data = [x for x in images_data if x not in test_images_data]
        training_masks_data = [f.replace('/images/', '/masks/') for f in training_images_data]

        # Old random sampling method for 70:30 data split
        # random.shuffle(images_data)
        # training_images_data = images_data[:int(0.7*len(images_data))]
        # training_masks_data = [f.replace('/images/', '/masks/') for f in training_images_data]
        # test_images_data  = images_data[int(0.7*len(images_data)):]
        # test_masks_data = [f.replace('/images/', '/masks/') for f in test_images_data]

        for f in training_images_data:
            shutil.copy(os.path.join(data_copy_dir,'images',f), os.path.join(training_data_dir,'images',f))

        for f in training_masks_data:
            shutil.copy(os.path.join(data_copy_dir,'masks',f), os.path.join(training_data_dir,'masks',f))

        for f in test_images_data:
            shutil.copy(os.path.join(data_copy_dir,'images',f), os.path.join(test_data_dir,'images',f))

        for f in test_masks_data:
            shutil.copy(os.path.join(data_copy_dir,'masks',f), os.path.join(test_data_dir,'masks',f))

        print ('Done!')

        training_data_images = []
        training_data_masks = []
        test_data_images = []
        test_data_masks = []

        print ('Loading data...')

        for imagepath, maskpath in zip(natsorted(glob.glob(training_data_dir+'/images/*')), natsorted(glob.glob(training_data_dir+'/masks/*'))):
            image = Image.open(imagepath).resize((512, 512), resample=Image.BILINEAR)
            mask = Image.open(maskpath).resize((512, 512), resample=Image.NEAREST)
            training_data_images.append(np.array(image))
            training_data_masks.append(np.array(mask))

        for imagepath, maskpath in zip(natsorted(glob.glob(test_data_dir+'/images/*')), natsorted(glob.glob(test_data_dir+'/masks/*'))):
            image = Image.open(imagepath).resize((512, 512), resample=Image.BILINEAR)
            mask = Image.open(maskpath).resize((512, 512), resample=Image.NEAREST)
            test_data_images.append(np.array(image))
            test_data_masks.append(np.array(mask))

        training_data_images = np.array(training_data_images).astype(np.float32)
        training_data_masks = np.array(training_data_masks).astype(np.float32)
        test_data_images = np.array(test_data_images).astype(np.float32)
        test_data_masks = np.array(test_data_masks).astype(np.float32)

        print ('Done!')

        print ('Running normalisation...')

        for idx, img in enumerate(training_data_images):
            training_data_images[idx] = (img-np.min(img))/(np.max(img)-np.min(img))

        for idx, img in enumerate(training_data_masks):
            if np.sum(img) > 0:
                img[img < (np.min(img)+np.max(img))/2] = 0.
                img[img >= (np.min(img)+np.max(img))/2] = 1.
                training_data_masks[idx] = img

        for idx, img in enumerate(test_data_images):
            test_data_images[idx] = (img-np.min(img))/(np.max(img)-np.min(img))

        for idx, img in enumerate(test_data_masks):
            if np.sum(img) > 0:
                img[img < (np.min(img)+np.max(img))/2] = 0.
                img[img >= (np.min(img)+np.max(img))/2] = 1.
                test_data_masks[idx] = img

        print ('Done!')

        print ('Checking nan...')

        if np.isnan(training_data_images).any() or np.isnan(training_data_masks).any() or np.isnan(test_data_images).any() or np.isnan(test_data_masks).any():
            print ('NaN value detected. Repeating the augmentation process again...')
        else:
            nandetected = True

    print ('Done!')

    training_data_images = training_data_images[..., np.newaxis]
    training_data_masks = training_data_masks[..., np.newaxis]
    test_data_images = test_data_images[..., np.newaxis]
    test_data_masks = test_data_masks[..., np.newaxis]

    return (training_data_images, training_data_masks, test_data_images, test_data_masks)
Example #25
0
 def update(self):
     if self.updater.need_update():
         result = self.updater.update()
         cleanup.clean(cleanup.FOLDER_STRUCTURE)
         return result
class TestStampy(TestCase):
    cleanup.clean()

    def test_kick(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/kick"}}]

        stampy.stampy.process(messages)

    def test_whois(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/whois"}}]

        stampy.stampy.process(messages)

    def test_deopall(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/deopall"}}]

        stampy.stampy.process(messages)

    def test_opall(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/opall"}}]

        stampy.stampy.process(messages)

    def test_mute(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/mute"}}]

        stampy.stampy.process(messages)

    def test_unmute(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/unmute"}}]

        stampy.stampy.process(messages)

    def test_topic(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/topic test channel"}}]

        stampy.stampy.process(messages)

    def test_deop(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/deop"}}]

        stampy.stampy.process(messages)

    def test_op(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/op"}}]

        stampy.stampy.process(messages)

    def test_unban(self):
        true = True
        messages = [{"update_id": 240168933,
                     "message": {"message_id": 4831,
                                 "from": {"id": 5812695, "first_name": "Pablo", "last_name": "Iranzo G\u00f3mez",
                                          "username": "******", "language_code": "es"},
                                 "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                          "all_members_are_administrators": true}, "date": 1497476585,
                                 "reply_to_message": {"message_id": 4830, "from": {"id": 5812695, "first_name": "Pablo",
                                                                                   "last_name": "Iranzo G\u00f3mez",
                                                                                   "username": "******",
                                                                                   "language_code": "es"},
                                                      "chat": {"id": -158164217, "title": "BOTdevel", "type": "group",
                                                               "all_members_are_administrators": true},
                                                      "date": 1497476576, "text": "test"}, "text": "/unban"}}]

        stampy.stampy.process(messages)
Example #27
0
#!/usr/bin/env python
# coding=utf-8

import cleanup
cleanup.clean(cleanup.FOLDER_STRUCTURE)

import datetime
import os
import sys

import core
from core import logger, main_db
from core.auto_process import comics, games, movies, music, tv
from core.auto_process.common import ProcessResult
from core.user_scripts import external_script
from core.utils import char_replace, convert_to_ascii, plex_update, replace_links
from six import text_type


def process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent):
    status = 1  # 1 = failed | 0 = success
    root = 0
    found_file = 0

    if client_agent != 'manual' and not core.DOWNLOADINFO:
        logger.debug('Adding TORRENT download info for directory {0} to database'.format(input_directory))

        my_db = main_db.DBConnection()

        input_directory1 = input_directory
        input_name1 = input_name
Example #28
0
 def update(self):
     if self.updater.need_update():
         result = self.updater.update()
         cleanup.clean('core', 'libs')
         return result
Example #29
0
        textPrint.indent()

        for i in range( hats ):
            hat = joystick.get_hat( i )
            textPrint.print(screen, "Hat {} value: {}".format(i, str(hat)) )
        textPrint.unindent()
        
        textPrint.unindent()
        
    new_a = joystick.get_axis(0) + float(1)
    new_a = (new_a * float(-1)) + float(2)
    new_a = (new_a * float(85)) + float(10)
    new_a = int(new_a)
    
    servo.update(new_a)
    
    if joystick.get_button(3) == 1:
        done = True
        
    # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT
    
    # Go ahead and update the screen with what we've drawn.
    pygame.display.flip()

    # Limit to 20 frames per second
    clock.tick(60)
    
# Close the window and quit.
pygame.quit ()
cleanup.clean()
Example #30
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_createfowrard(self):
        stampy.plugin.forward.createforward(source=1, target=2)
        for each in stampy.plugin.forward.getforward(source=1):
            self.assertEqual(each, u"2")

    def test_forwardlist(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'/forward list',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)

    def test_forwardadd(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'/forward 211213=2123123',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)

    def test_forwarddelete(self):
        messages = [{
            u'message': {
                u'date': 1478361249,
                u'text': u'/forward delete 211213=2123123',
                u'from': {
                    u'username': u'iranzo',
                    u'first_name': u'Pablo',
                    u'last_name': u'Iranzo G\xf3mez',
                    u'id': 5812695
                },
                u'message_id': 108,
                u'chat': {
                    u'all_members_are_administrators': True,
                    u'type': u'group',
                    u'id': -158164217,
                    u'title': u'BOTdevel'
                }
            },
            u'update_id': 837253571
        }]
        stampy.stampy.process(messages)
Example #31
0
def test_cleanup():
    import cleanup
    cleanup.clean(cleanup.FOLDER_STRUCTURE)
Example #32
0
class TestStampy(TestCase):
    cleanup.clean()

    def test_00stats(self):
        # test that no empty [] groups are added
        stampy.plugin.stats.updatestats(type='chat', id=-1, name="Test",
                                        date=False, memberid=[])
        self.assertEqual(stampy.plugin.stats.getstats(id=-1, type='chat'),
                         ('chat', -1, u"Test", u'False', 1, []))

    def test_01pingchat(self):
        stampy.plugin.stats.pingchat(-1)
        (type, id, name, date, count, memberid) = stampy.plugin.stats.getstats(
            type='chat', id=-1)
        self.assertEqual(stampy.plugin.stats.getstats(id=-1, type='chat'),
                         ('chat', -1, u"Test", date, count, []))

    def test_02statsshow(self):
        messages = [{u'message': {u'date': 1478361249, u'text': u'/stats show',
                                  u'from': {u'username': u'iranzo',
                                            u'first_name': u'Pablo',
                                            u'last_name': u'Iranzo G\xf3mez',
                                            u'id': 5812695}, u'message_id': 108,
                                  u'chat': {u'all_members_are_administrators': True,
                                            u'type': u'group', u'id': -158164217,
                                            u'title': u'BOTdevel'}},
                     u'update_id': 837253571}]
        stampy.stampy.process(messages)

    def test_02statsshowtype(self):
        messages = [{u'message': {u'date': 1478361249, u'text': u'/stats show chat',
                                  u'from': {u'username': u'iranzo',
                                            u'first_name': u'Pablo',
                                            u'last_name': u'Iranzo G\xf3mez',
                                            u'id': 5812695}, u'message_id': 108,
                                  u'chat': {u'all_members_are_administrators': True,
                                            u'type': u'group', u'id': -158164217,
                                            u'title': u'BOTdevel'}},
                     u'update_id': 837253571}]
        stampy.stampy.process(messages)

    def test_02statssearch(self):
        messages = [{u'message': {u'date': 1478361249, u'text': u'/stats search',
                                  u'from': {u'username': u'iranzo',
                                            u'first_name': u'Pablo',
                                            u'last_name': u'Iranzo G\xf3mez',
                                            u'id': 5812695}, u'message_id': 108,
                                  u'chat': {u'all_members_are_administrators': True,
                                            u'type': u'group', u'id': -158164217,
                                            u'title': u'BOTdevel'}},
                     u'update_id': 837253571}]
        stampy.stampy.process(messages)

    def test_dochatcleanup(self):
        stampy.plugin.stats.dochatcleanup()

    def test_statsgetout(self):
        messages = [{u'message': {u'date': 1478361249, u'text': u'/getout',
                                  u'from': {u'username': u'iranzo',
                                            u'first_name': u'Pablo',
                                            u'last_name': u'Iranzo G\xf3mez',
                                            u'id': 5812695}, u'message_id': 108,
                                  u'chat': {u'all_members_are_administrators': True,
                                            u'type': u'group', u'id': -234,
                                            u'title': u'BOTdevel'}},
                     u'update_id': 837253571}]
        stampy.stampy.process(messages)

    def test_allping(self):
        messages = [{u'message': {u'date': 1478361249, u'text': u'@all',
                                  u'from': {u'username': u'iranzo',
                                            u'first_name': u'Pablo',
                                            u'last_name': u'Iranzo G\xf3mez',
                                            u'id': 5812695}, u'message_id': 108,
                                  u'chat': {u'all_members_are_administrators': True,
                                            u'type': u'group', u'id': -15124124,
                                            u'title': u'BOTdevel'}},
                     u'update_id': 837253571}]
        stampy.stampy.process(messages)

    def test_allkarma(self):
        messages = [{u'message': {u'date': 1478361249, u'text': u'@all++',
                                  u'from': {u'username': u'iranzo',
                                            u'first_name': u'Pablo',
                                            u'last_name': u'Iranzo G\xf3mez',
                                            u'id': 5812695}, u'message_id': 108,
                                  u'chat': {u'all_members_are_administrators': True,
                                            u'type': u'group', u'id': -15124124,
                                            u'title': u'BOTdevel'}},
                     u'update_id': 837253571}]
        stampy.stampy.process(messages)
Example #33
0
def test_cleanup():
    import cleanup
    cleanup.clean(cleanup.FOLDER_STRUCTURE)
Example #34
0
        if request.method in ('PUT',"POST"):
            return redirect(url_for('light'), code=302)
        else:
            return helpers.toggle()

    @app.route('/button')

    @app.route('/button/short', methods=['GET', 'PUT', 'POST'])
    def short():
        return power.short()

    @app.route('/button/long', methods=['GET', 'PUT', 'POST'])
    def long():
        return power.long()

    @app.route('/button/state', methods=['GET', 'PUT', 'POST'])
    def state():
        return powerstate.status(),

    @app.route('/light/state', methods=['GET', 'PUT', 'POST'])
    def lightstate():
        return light.status(),

    if __name__ == '__main__':
        app.debug = True
        app.run(host="0.0.0.0",)# ssl_context=context)

except:
    cleanup.clean()
    print "cleaned"