Esempio n. 1
0
def react():
    observation = str(request.get_json())
    response = muterun_rb('logic.rb', observation)

    if response.exitcode == 0:
        print(response.stdout.decode("utf-8").rstrip())
    else:
        print(response.stderr.decode("utf-8").rstrip())

    return jsonify(response.stdout.decode("utf-8").rstrip())
Esempio n. 2
0
def get_lyrics(artist_name):
    artist_nameq = '"' + artist_name + '"'
    print("Retrieving lyrics for: {}".format(artist_nameq))
    if os.path.exists(artist_name):
        with open(artist_name, 'r') as artist_file:
            return list(filter(lambda x: len(x) > 0, artist_file.read().split()))
    rapgenius_result = muterun_rb('getLyrics.rb', artist_nameq)
    if rapgenius_result.exitcode != 0:
        print("Error retrieving lyrics: " + rapgenius_result.stderr.decode("utf-8"))
        sys.exit(-1)
    lyrics = tag_regex.sub("", rapgenius_result.stdout.decode("utf-8"))
    lyrics = nl_regex.sub(".\n", lyrics).lower()
    with open(artist_name, 'w') as artist_file:
        artist_file.write(lyrics)
    words = lyrics.split()
    return  list(filter(lambda x: len(x) > 0, words))
Esempio n. 3
0
    def _set_linguist(self):
        response = muterun_rb(
            os.path.join(root_path, 'persper', 'util', 'linguist.rb'),
            self._repo_path)

        if response.exitcode == 0:
            lang_dict = json.loads(response.stdout)
            total_lines = sum(lang_dict.values())

            for k in lang_dict.keys():
                lang_dict[k] = lang_dict[k] * 1.0 / total_lines

            js = Linguist.JAVASCRIPT.value
            ts = Linguist.TYPESCRIPT.value
            vue = Linguist.VUE.value

            _logger.info(lang_dict)
            if vue in lang_dict:
                _logger.info("Merging Vue to Javascript...")
                if js not in lang_dict:
                    lang_dict[js] = 0
                lang_dict[js] += lang_dict[vue]
                del lang_dict[vue]
                _logger.info(lang_dict)

            if ts in lang_dict:
                _logger.info("Merging TypeScript to JavaScript...")
                if js not in lang_dict:
                    lang_dict[js] = 0
                lang_dict[js] += lang_dict[ts]
                del lang_dict[ts]
                _logger.info(lang_dict)

            # intersect with what languages we support
            for lang, value in lang_dict.items():
                if lang in self._supported_analyzers().keys():
                    self._linguist[lang] = value

            _logger.info(self._linguist)

        else:
            _logger.info('Analyzing Language Error from Linguist')
Esempio n. 4
0
          "client_id": "",
          "type": "service_account"
        }
"""
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)
if gc:
  logging.info('OAuth succeeded')
else:
  logging.warn('Oauth failed')

now = time.strftime("%c")

# get data from ruby script
response = muterun_rb('script')
if response:
  logging.info('Data collected')
else:
  logging.warn('Could not collect data')

csv = response.stdout
csv = re.sub('/|"|,[0-9][0-9][0-9]Z|Z', '', csv)
csv_lines = csv.split('\n')

#get columns and rows for cell list
column = len(csv_lines[0].split(","))
row = 1
for line in csv_lines:
  row += 1
Esempio n. 5
0
 def test_muterun_rb_fail(self):
     out = muterun_rb(self.ruby_fail_path)
     self.assertEqual(b'error\n', out.stderr)
     self.assertEqual(b'', out.stdout)
     self.assertEqual(1, out.exitcode)
Esempio n. 6
0
 def test_muterun_rb_success(self):
     out = muterun_rb(self.ruby_success_path)
     self.assertEqual(b'success\n', out.stdout)
     self.assertEqual(0, out.exitcode)
     self.assertEqual(b'', out.stderr)
Esempio n. 7
0
 def test_muterun_rb_fail(self):
     out = muterun_rb(self.ruby_fail_path)
     self.assertEqual(b'error\n', out.stderr)
     self.assertEqual(b'', out.stdout)
     self.assertEqual(1, out.exitcode)
Esempio n. 8
0
 def test_muterun_rb_success(self):
     out = muterun_rb(self.ruby_success_path)
     self.assertEqual(b'success\n', out.stdout)
     self.assertEqual(0, out.exitcode)
     self.assertEqual(b'', out.stderr)
Esempio n. 9
0
          "type": "service_account"
        }
"""
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'],
                                            json_key['private_key'], scope)
gc = gspread.authorize(credentials)
if gc:
    logging.info('OAuth succeeded')
else:
    logging.warn('Oauth failed')

now = time.strftime("%c")

# get data from ruby script
response = muterun_rb('script')
if response:
    logging.info('Data collected')
else:
    logging.warn('Could not collect data')

csv = response.stdout
csv = re.sub('/|"|,[0-9][0-9][0-9]Z|Z', '', csv)
csv_lines = csv.split('\n')

#get columns and rows for cell list
column = len(csv_lines[0].split(","))
row = 1
for line in csv_lines:
    row += 1
Esempio n. 10
0
def adocToHTML(file):
    return muterun_rb(asciidoctor, file)
Esempio n. 11
0
def adocToPDF(file):
    return muterun_rb(asciidoctor_pdf, file)