Ejemplo n.º 1
0
 def test_is_alphabetized(self):
     member_list = load_file('gryffindor.txt')
     self.assertFalse(is_alphabetized(member_list, order_first_name))
     self.assertFalse(is_alphabetized(member_list, order_last_name))
     member_list = load_file('sorted_first_name.txt')
     self.assertTrue(is_alphabetized(member_list, order_first_name))
     member_list = load_file('sorted_last_name.txt')
     self.assertTrue(is_alphabetized(member_list, order_last_name))
Ejemplo n.º 2
0
def command_load_plugin(msg: twitchirc.ChannelMessage):
    argv = msg.text.split(' ')
    if len(argv) > 1:
        argv.pop(0)  # Remove the command name
    try:
        pl = main.load_file(argv[0])
        return f'Successfully loaded plugin: {pl.name}'
    except Exception as e:
        return f'An exception was encountered: {e!r}'
def test_load_file(mocked_gcs, test_file):
    event = {
        "bucket": "batch-import-slack-export-nonprod-1879",
        "name": "google-cloud/2020-06-24.json",
        "foo": "bar",
    }
    # when calling the GCS API, we expect data to come back in a certain way
    channel, data = main.load_file(**event)
    assert data is not None
    assert len(data) == 4  # messages that day
Ejemplo n.º 4
0
	def on_file_select_OK_clicked(self, object, data=None):
		print "OK Clicked"
		sel = self.tree.get_selection()
		(model,rows)=sel.get_selected()
		self.filename="programs/"+model[rows][1]
		self.load_prog(load_file(self.filename))
		self.liststore.clear()
		self.name[:]=[]
		self.date[:]=[]
		self.time[:]=[]

		self.file_select.hide()
Ejemplo n.º 5
0
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
import datetime
import typing

import aiohttp

try:
    # noinspection PyPackageRequirements
    import main

except ImportError:
    import util_bot as main

    exit()
main.load_file('plugins/plugin_help.py')
try:
    import plugin_plugin_help as plugin_help
except ImportError:
    import plugins.plugin_help as plugin_help

    exit(1)
try:
    import plugin_plugin_manager as plugin_manager
except ImportError:
    import plugins.plugin_manager as plugin_manager
try:
    import plugin_prometheus
except ImportError:
    plugin_prometheus = None
    if typing.TYPE_CHECKING:
Ejemplo n.º 6
0
    def display_graph(self):
        self.algorithm = self.combobox_algs.get()
        self.mode = self.combobox_types.get()
        print(self.mode)
        print(self.algorithm)


        if self.mode == "Google":
            self.file_path = "googl.us.txt"
        elif self.mode == "Apple":
            self.file_path = "aapl.us.txt"
        elif self.mode == "Amazon":
            self.file_path = "amzn.us.txt"
        elif self.mode == "Coca Cola":
            self.file_path = "ko.us.txt"


        # df = load_file(self.file_path)

        df = pd.read_csv(self.file_path)

        # if self.algorithm == "SVM":
        #     print("Svm izabran")
        #     # self.y_train, self.y_val, self.y_predict = svm_prediction(df)
        #
        #     new_df = preprocess(load_file(self.file_path))
        #     x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
        #     self.y_predict = svm_prediction(df, x_train, y_train, x_valid, y_valid)
        #     self.y_train = y_train
        #     self.y_val = y_valid



        if self.algorithm == "Moving average":
            print("MA izabran")
            #NISAM TESTIRAO MA, TREBA MODIFIKOVATI

            new_df = preprocess(load_file(self.file_path))
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = predict_ma(df)
            self.y_train = y_train
            self.y_val = y_valid

        elif self.algorithm == "KNN":
            print("KNN izabran")
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = knn_predict(x_train, y_train, x_valid)
            self.y_train = y_train
            self.y_val = y_valid

            plt.plot(self.y_train)
            plt.plot(self.y_val)
            plt.plot(self.y_predict)
            plt.show()

            # plot_graph(self.train, self.valid, self.y_predict)
        elif self.algorithm == "Auto Arima":
            print("Auto Arima izabran")
            # UBACI OVDE POZIV AUTO ARIMA METODE
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = auto_arima_predict(df)
            self.y_train = y_train
            self.y_val = y_valid

        elif self.algorithm == "Linear Regression":
            print("Linear Regression izabran")
            # UBACI OVDE POZIV LINEAR REGRESSION
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = linearregression.run_regression(x_train, y_train, x_valid, y_valid)
            self.y_train = y_train
            self.y_val = y_valid

            plt.plot(self.y_train)
            plt.plot(self.y_val)
            plt.plot(self.y_predict)
            plt.show()
        elif self.algorithm == "Prophet":
            print("Prophet")
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = prophet_predict(self.train, self.valid)
            self.y_train = y_train
            self.y_val = y_valid

            plt.plot(self.y_train)
            plt.plot(self.y_val)
            plt.plot(self.y_predict)
            plt.show()


        print(self.y_predict)

        print("Zavrsio obucavanje i predikciju")


        p1 = figure(x_axis_type="datetime", title="Stock Closing Prices")
        p1.grid.grid_line_alpha = 0.3
        p1.xaxis.axis_label = 'Date'
        p1.yaxis.axis_label = 'Price'

        plot_dates = df['Date']
        print(self.valid)
        plot_dates = plot_dates[-len(self.y_predict):]
        p1.line(plot_dates, self.valid['Close'], color='#A6CEE3', legend=self.mode)
        p1.line(plot_dates, self.y_predict, color='#B2DF8A', legend="Predicted "+self.mode)

        output_file("stocks.html", title="Stocks prediction")

        show(gridplot([[p1]], plot_width=500, plot_height=500))
Ejemplo n.º 7
0
except ImportError:
    import util_bot as main

    exit()

try:
    # noinspection PyPackageRequirements
    import plugin_plugin_manager as plugin_manager

except ImportError:
    if typing.TYPE_CHECKING:
        import plugins.plugin_manager as plugin_manager
    else:
        raise

main.load_file('plugins/plugin_help.py')
try:
    import plugin_plugin_help as plugin_help
except ImportError:
    if typing.TYPE_CHECKING:
        import plugins.plugin_help as plugin_help
    else:
        raise

main.load_file('plugins/plugin_chat_cache.py')
try:
    import plugin_chat_cache
except ImportError:
    if typing.TYPE_CHECKING:
        from plugins.plugin_chat_cache import Plugin as PluginChatCache
                            song += '-'
                if icon_idx + 1 < len(instrument):
                    song += ' '
            if instr_idx + 1 < len(song_line):
                song += ' '
    return song


# ========== MAIN SCRIPT================
mycwd = os.getcwd()
os.chdir("..")

print('===== TRANSPOSITION TOOL IN THE CHROMATIC SCALE =====')
first_line = input('Type or copy-paste notes, or enter file name (in ' + os.path.normpath(SONG_DIR_IN) + '/): ').strip()

fp = load_file(SONG_DIR_IN, first_line)  # loads file or asks for next line

song_lines = read_lines(fp, first_line)

try:
    note_shift = int(input('Transposition ? (-12 ; +12): ').strip())
except ValueError:
    note_shift = 0

skyparser = SongParser()
skyparser.set_delimiters(ICON_DELIMITER, PAUSE, QUAVER_DELIMITER, COMMENT_DELIMITER, REPEAT_INDICATOR)
possible_modes = skyparser.get_possible_modes(song_lines)

if len(possible_modes) > 1:
    print('\nSeveral possible notations detected.')
    song_notation = ask_for_mode(possible_modes)
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
import socket
import threading

import twitchirc

try:
    # noinspection PyUnresolvedReferences
    import main
except ImportError:
    # noinspection PyPackageRequirements
    import util_bot as main

    raise

main.load_file('plugins/plugin_help.py')
try:
    import plugin_plugin_help as plugin_help
except ImportError:
    import plugins.plugin_help as plugin_help

    exit(1)

try:
    import plugin_plugin_manager as plugin_manager
except ImportError:
    import plugins.plugin_manager as plugin_manager

    exit(1)

main.load_file('plugins/plugin_prefixes.py')
Ejemplo n.º 10
0
 def test_alphabetize_by_last(self):
     self.maxDiff = None
     member_list = load_file('gryffindor.txt')
     solution = load_file('sorted_last_name.txt')
     (sorted_list, cost) = alphabetize(member_list, order_last_name)
     self.assertEqual(sorted_list, solution)
Ejemplo n.º 11
0
    exit(1)

try:
    # noinspection PyPackageRequirements
    import main
except ImportError:
    import util_bot as main

    exit(1)
try:
    import plugin_plugin_manager as plugin_manager
except ImportError:
    import plugins.plugin_manager as plugin_manager

main.load_file('plugins/plugin_hastebin.py')
try:
    import plugin_hastebin as plugin_hastebin
except ImportError:
    from plugins.plugin_hastebin import Plugin as PluginHastebin

    plugin_hastebin: PluginHastebin

import random

import twitchirc

__meta_data__ = {'name': 'plugin_cancer', 'commands': []}

log = main.make_log_function('cancerous_plugin')
with open(__file__, 'r') as f:
Ejemplo n.º 12
0
    async def audio_player_task(self):
        while True:
            self.next.clear()
            self.now = None

            if self.previous_message:
                await self.previous_message.delete()
                self.previous_message = None

            if self._loop:
                if self.current:
                    await self.songs.put(self.current)

            try:
                async with timeout(5):
                    self.current = await self.songs.get()
            except asyncio.TimeoutError:
                self.current = None
                if self._autoplay:
                    if not self.voice:
                        self.bot.loop.create_task(self.stop())
                        self.exists = False
                        return
                    INFO("Fetching autoplay List")
                    if not self.autoplaylist:
                        self.autoplaylist = list(load_file("autoplaylist.txt"))
                    while self.autoplaylist:
                        random_link = random.choice(self.autoplaylist)
                        INFO(f"Trying {random_link} from autoplaylist")
                        self.autoplaylist.remove(random_link)
                        song_url, source_type, playlist = SourceDL.get_type(
                            random_link)
                        source_init = SourceDL.Source(self._ctx,
                                                      source_type=source_type,
                                                      loop=self.bot.loop)
                        if playlist:
                            playlist_info = await source_init.get_playlist_info(
                                song_url)
                            INFO(
                                f"Adding {playlist_info.song_num} songs from {random_link}"
                            )
                            try:
                                sources = await source_init.get_playlist(
                                    song_url)
                            except SourceDL.SourceError:
                                continue
                            else:
                                if source_type == "GDrive":
                                    for num, each_source in enumerate(sources):
                                        sources[
                                            num] = f"https://drive.google.com/file/d/{each_source}/view"
                            self.autoplaylist = sources
                            continue
                        else:
                            try:
                                source = await source_init.create_source(
                                    song_url)
                            except SourceDL.SourceError:
                                pass
                            else:
                                song = Song(source)
                                await self._ctx.voice_state.songs.put(song)
                        self.current = await self.songs.get()
                        if self.current:
                            break
                        continue
                    if not self.current:
                        self.bot.loop.create_task(self.stop())
                        self.exists = False
                        return
                else:
                    self.bot.loop.create_task(self.stop())
                    self.exists = False
                    return
            for each_song in self.song_history:
                if self.current.source.data.title == each_song.source.data.title:
                    self.song_history.remove(each_song)
            self.song_history.insert(0, self.current)
            self.current.source.volume = self._volume
            await self.current.source.ready_download()
            with open(
                    f"audio_cache\\{self.current.source.data.expected_filename}",
                    'rb') as f:
                source = discord.FFmpegPCMAudio(f, pipe=True)
            self.voice.play(source, after=self.play_next_song)
            #await self.current.source.bot.change_presence(activity=discord.Game(f"{self.current.source.title}"))
            embed, thumbnail = self.current.create_embed()
            if thumbnail:
                self.previous_message = await self.current.source.channel.send(
                    embed=embed, file=thumbnail)
            else:
                self.previous_message = await self.current.source.channel.send(
                    embed=embed)
            await self.next.wait()
Ejemplo n.º 13
0
    import main
except ImportError:
    # noinspection PyUnreachableCode
    if False:
        import util_bot as main
    else:
        import main_stub
        # noinspection PyUnresolvedReferences
        import main  # load the Fake from main_stub

try:
    import plugin_plugin_manager as plugin_manager
except ImportError:
    import plugins.plugin_manager as plugin_manager

main.load_file('plugins/plugin_prefixes.py')

try:
    import plugin_plugin_prefixes as plugin_prefixes
except ImportError:
    import plugins.plugin_prefixes as plugin_prefixes

__meta_data__ = {'name': 'plugin_help', 'commands': []}
log = main.make_log_function('help')
SECTION_LINKS = 0
SECTION_COMMANDS = 1
SECTION_ARGS = 2
SECTION_MISC = 7
all_help: Dict[int, Union[Dict[str, Tuple[int, str]], Dict[str, str]]] = {
    SECTION_LINKS: {  # links
        # 'source': (1, 'target') <=> (section, target)
Ejemplo n.º 14
0
    exit()

import twitchirc

__meta_data__ = {'name': 'auto_load', 'commands': []}
log = main.make_log_function('auto_load')

log('info', 'Plugin `auto_load` loaded')

if 'plugins' in main.bot.storage.data:
    if main.bot.storage['plugins'] == 'auto':
        for i in os.listdir('plugins'):
            log('debug', f'Trying to load file: {i}')
            try:
                main.load_file(i)
            except Exception as e:
                log('err', f'Failed to load: {e}')
                for i in traceback.format_exc(30).split('\n'):
                    log('err', i)
    else:
        for i in main.bot.storage['plugins']:
            log('debug', f'Trying to load file: {i}')
            try:
                main.load_file(i)
            except Exception as e:
                log('err', f'Failed to load: {e}')
                for i in traceback.format_exc(30).split('\n'):
                    log('err', i)
else:
    main.bot.storage['plugins'] = []
Ejemplo n.º 15
0
    exit(1)

try:
    # noinspection PyPackageRequirements
    import main
except ImportError:
    import util_bot as main

    exit(1)
try:
    import plugin_plugin_manager as plugin_manager
except ImportError:
    import plugins.plugin_manager as plugin_manager

main.load_file('plugins/plugin_hastebin.py')
try:
    import plugin_hastebin as plugin_hastebin
except ImportError:
    from plugins.plugin_hastebin import Plugin as PluginHastebin

    plugin_hastebin: PluginHastebin

main.load_file('plugins/plugin_emotes.py')
try:
    import plugin_emotes as plugin_emotes
except ImportError:
    from plugins.plugin_emotes import Plugin as PluginEmotes

    plugin_emotes: PluginEmotes