Ejemplo n.º 1
0
 def test_generate_text(self):
     self.assertEqual(AppService.generate_text(['Hello', 'World']),
                      ' Hello World')
     self.assertEqual(
         AppService.generate_text(
             ['Todavia,', 'o', 'início', 'da', 'atividade', 'geral']),
         ' Todavia, o início da atividade geral')
Ejemplo n.º 2
0
    def test_get_content(self):
        self.assertEqual(
            AppService.get_content('<link>Hello World</link>',
                                   r'<link>(.*?)</link>', 0), 'Hello World')

        self.assertEqual(
            AppService.get_content(
                '<title>Hello World</title><name>Test</name><title>New Hello '
                'World</title><name>Teste 2</name>', r'<title>(.*?)</title>',
                1), 'New Hello World')
Ejemplo n.º 3
0
 def test_get_title(self):
     self.assertEqual(
         AppService.get_title(
             '<title><![CDATA[Hello World]]></title><title><![CDATA[No Hello World]]></title>',
             0), 'Hello World')
     self.assertEqual(
         AppService.get_title(
             '<title><![CDATA[Hello World]]></title><title><![CDATA[No Hello World]]></title>',
             1), 'No Hello World')
     self.assertNotEqual(
         AppService.get_title(
             '<title><![CDATA[Hello World]]></title><title><![CDATA[No Hello World]]></title>',
             0), 'No Hello World')
Ejemplo n.º 4
0
 def test_get_link(self):
     self.assertEqual(
         AppService.get_link(
             '<link>Hello World</link><link>No Hello World</link>', 0),
         'Hello World')
     self.assertEqual(
         AppService.get_link(
             '<link>Hello World</link><link>No Hello World</link>', 1),
         'No Hello World')
     self.assertNotEqual(
         AppService.get_link(
             '<link>Hello World</link><link>No Hello World</link>', 0),
         'No Hello World')
Ejemplo n.º 5
0
    def test_xml_to_json(self):
        xml = '<item>' \
              '<title><![CDATA[Ford Ka e VW Gol automáticos]]></title>' \
              '<description>' \
              '<p>No programa <strong>DRIVE</strong> dessa semana<a href="google.com.br">Click aqui </a><img ' \
              'src="image.jpg"/></p>' \
              '</description>' \
              '</item>' \
              '<link>google.com.br</link>'

        feed = '{"feed": [{"item": {"title": "Ford Ka e VW Gol automáticos", "link": "google.com.br", "description": [{' \
               '"type": "text", "content": " No programa DRIVE dessa semanaClick aqui "}, {"type": "link", "content": [' \
               '"google.com.br"]}, {"type": "image", "content": ["image.jpg"]}]}}]}'
        self.assertEqual(AppService.xml_to_json(xml), feed)
Ejemplo n.º 6
0
def main():
    content = AppService.get_content_from_url()
    json = AppService.xml_to_json(content)
    logger.info("Result: %s", json)
Ejemplo n.º 7
0
import os
from datetime import datetime
import flask
from flask import request, Response, send_from_directory
from flask_cors import CORS
from app.service import AppService
from helpers import helper

app = flask.Flask(__name__)
app.config["DEBUG"] = True
# enabling cors for all
CORS(app)

service = AppService()

# todo: chang this result file path
UPLOAD_DIRECTORY = "./files"
UPLOAD_DIRECTORY = os.path.abspath(UPLOAD_DIRECTORY)


@app.route("/download", methods=['GET'])
def get_file():
    """Download a file."""
    path = service.result_csv
    service.write_output_csv()
    return send_from_directory(UPLOAD_DIRECTORY, filename=path, as_attachment=True)


@app.route("/get_table", methods=['GET'])
def get_table():
    result = service.get_json_df_response()