Beispiel #1
0
    def get(self):
        # Initialize list, dictionary, and variables
        resultDict = {}
        returnDict = {}
        codeVal = 200

        # Create object of tv feed web service class
        tfwsclass = tvfeedwebserviceclass.TVFeedWebServiceClass()

        # try to execute the command(s)
        try:
            # Store headers
            wsHead = dict(request.headers)

            # Set variable
            #reqPath = request.path

            # Check if headers were provided
            webserviceHeaderResponse = tfwsclass._checkHeaders(wsHead)

            # Check if element exists
            if webserviceHeaderResponse.get('Status') != None:
                # Check if status is success
                if webserviceHeaderResponse['Status'] == 'Success':
                    # Set list
                    mandatoryParams = []

                    # Check payload
                    payloadResponse = tfwsclass._checkPayload(
                        request.method, request.args, mandatoryParams)

                    # Check if element exists
                    if payloadResponse.get('Status') != None:
                        # Check if status is success
                        if payloadResponse['Status'] == 'Success':
                            # Set variable
                            statusVal = 'Success'
                            messageVal = 'Processed request'
                            selectColumn = 'select titlelongreturn as "Title Long", titleshortreturn as "Title Short", publishdatereturn as "Publish Date", actionstatusreturn as "Action Status"'

                            # Initialize list
                            possibleParams = [
                                'titlelong', 'titleshort', 'actionstatus',
                                'limit', 'sort'
                            ]

                            # Extract tv feed
                            resultDict = tfwsclass._extractTVFeed(
                                'MariaDBSQLTV', 'extracting', '',
                                'extractmediafeed', 'extractTVFeed',
                                possibleParams, payloadResponse['Result'])
                            resultDict = tfwsclass._extractTVFeed(
                                'PGSQLTV', 'extracting', selectColumn,
                                'extractmediafeed', 'extractTVFeed',
                                possibleParams, payloadResponse['Result'])
                            resultDict = tfwsclass._extractTVFeed(
                                'MSSQLLTV', 'extracting', '',
                                'dbo.extractMediaFeed', 'extractTVFeed',
                                possibleParams, payloadResponse['Result'])
                            resultDict = tfwsclass._extractTVFeed(
                                'MSSQLWTV', 'extracting', '',
                                'dbo.extractMediaFeed', 'extractTVFeed',
                                possibleParams, payloadResponse['Result'])

                            # Check if there is data
                            if resultDict:
                                # Loop through sub elements
                                for systemEntries in resultDict:
                                    # Check if elements exists
                                    if systemEntries.get('SError') != None:
                                        # Store status value
                                        statusVal = systemEntries['SError']

                                        # Store message value
                                        messageVal = systemEntries['SMessage']

                                        # Set code
                                        codeVal = 500

                                        # Break out of loop
                                        break

                                # Check if status value is success
                                if statusVal == 'Success':
                                    # Store Message
                                    returnDict = {
                                        'Status': statusVal,
                                        'Message': messageVal,
                                        'Count': len(resultDict),
                                        'Result': resultDict
                                    }
                                else:
                                    # Store Message
                                    returnDict = {
                                        'Status': statusVal,
                                        'Message': messageVal,
                                        'Count': 0,
                                        'Result': []
                                    }
                            else:
                                # Store Message
                                returnDict = {
                                    'Status': 'Success',
                                    'Message': 'Processed request',
                                    'Count': 0,
                                    'Result': []
                                }
                        else:
                            # Store Message
                            returnDict = {
                                'Status': payloadResponse['Status'],
                                'Message': payloadResponse['Message'],
                                'Count': 0,
                                'Result': []
                            }

                            # Store code
                            codeVal = 400
                    else:
                        # Store Message
                        returnDict = {
                            'Status': 'Error',
                            'Message': 'Issue with payload check',
                            'Count': 0,
                            'Result': []
                        }

                        # Store code
                        codeVal = 400
                else:
                    # Store Message
                    returnDict = {
                        'Status': webserviceHeaderResponse['Status'],
                        'Message': webserviceHeaderResponse['Message'],
                        'Count': 0,
                        'Result': []
                    }

                    # Store code
                    codeVal = 400
            else:
                # Store Message
                returnDict = {
                    'Status': 'Error',
                    'Message': 'Issue with header check',
                    'Count': 0,
                    'Result': []
                }

                # Store code
                codeVal = 400
        # Catch exceptions
        except Exception as e:
            # Store Message
            returnDict = {
                'Status': 'Error',
                'Message': 'GET not implemented properly',
                'Count': 0,
                'Result': []
            }

            # Log message
            tfwsclass._setLogger('GET ' + str(e))

        # Return dictionary with code
        return returnDict, codeVal
Beispiel #2
0
    def delete(self):
        # Initialize list, dictionary, and variables
        resultDict = {}
        returnDict = {}
        codeVal = 200

        # Create object of tv feed web service class
        tfwsclass = tvfeedwebserviceclass.TVFeedWebServiceClass()

        # try to execute the command(s)
        try:
            # Store headers
            wsHead = dict(request.headers)

            ## Set variable
            #reqPath = request.path

            # Check if headers were provided
            webserviceHeaderResponse = tfwsclass._checkHeaders(wsHead)

            # Check if element exists
            if webserviceHeaderResponse.get('Status') != None:
                # Check if status is success
                if webserviceHeaderResponse['Status'] == 'Success':
                    # Set list
                    mandatoryParams = ['titleshort']

                    # Check payload
                    payloadResponse = tfwsclass._checkPayload(
                        request.method, request.data, mandatoryParams)

                    # Check if element exists
                    if payloadResponse.get('Status') != None:
                        # Check if status is success
                        if payloadResponse['Status'] == 'Success':
                            # Set variable
                            statusVal = 'Success'
                            messageVal = 'Processed request'

                            # Initailize list
                            possibleParams = [
                                'titlelong', 'titleshort', 'titleshortold',
                                'publishdate', 'actionstatus'
                            ]
                            removeParams = [
                                'titlelong', 'titleshortold', 'publishdate',
                                'actionstatus'
                            ]

                            # Delete tv feed
                            resultDict = tfwsclass._insertupdatedeleteTVFeed(
                                'MariaDBSQLTV', 'deleting',
                                'insertupdatedeletemediafeed',
                                'deleteTVFeedTitleShort', possibleParams,
                                payloadResponse['Result'], removeParams)
                            resultDict = tfwsclass._insertupdatedeleteTVFeed(
                                'PGSQLTV', 'deleting',
                                'insertupdatedeletemediafeed',
                                'deleteTVFeedTitleShort', possibleParams,
                                payloadResponse['Result'], removeParams)
                            resultDict = tfwsclass._insertupdatedeleteTVFeed(
                                'MSSQLLTV', 'deleting',
                                'dbo.insertupdatedeleteMediaFeed',
                                'deleteTVFeedTitleShort', possibleParams,
                                payloadResponse['Result'], removeParams)
                            resultDict = tfwsclass._insertupdatedeleteTVFeed(
                                'MSSQLWTV', 'deleting',
                                'dbo.insertupdatedeleteMediaFeed',
                                'deleteTVFeedTitleShort', possibleParams,
                                payloadResponse['Result'], removeParams)

                            # Loop through sub elements
                            for systemEntries in resultDict:
                                # Check if elements exists
                                if systemEntries.get('SError') != None:
                                    # Store status value
                                    statusVal = systemEntries['SError']

                                    # Store message value
                                    messageVal = systemEntries['SMessage']

                                    # Set code
                                    codeVal = 500

                                    # Break out of the loop
                                    break

                            if statusVal == 'Success':
                                # Store Message
                                returnDict = {
                                    'Status': statusVal,
                                    'Message': messageVal,
                                    'Count': len(resultDict),
                                    'Result': resultDict
                                }
                            else:
                                # Store Message
                                returnDict = {
                                    'Status': statusVal,
                                    'Message': messageVal,
                                    'Count': 0,
                                    'Result': []
                                }
                        else:
                            # Store Message
                            returnDict = {
                                'Status': payloadResponse['Status'],
                                'Message': payloadResponse['Message'],
                                'Count': 0,
                                'Result': []
                            }

                            # Store code
                            codeVal = 400
                    else:
                        # Store Message
                        returnDict = {
                            'Status': 'Error',
                            'Message': 'Issue with payload check',
                            'Count': 0,
                            'Result': []
                        }

                        # Store code
                        codeVal = 400
                else:
                    # Store Message
                    returnDict = {
                        'Status': webserviceHeaderResponse['Status'],
                        'Message': webserviceHeaderResponse['Message'],
                        'Count': 0,
                        'Result': []
                    }
            else:
                # Store Message
                returnDict = {
                    'Status': 'Error',
                    'Message': 'Issue with header check',
                    'Count': 0,
                    'Result': []
                }
        # Catch exceptions
        except Exception as e:
            # Store Message
            returnDict = {
                'Status': 'Error',
                'Message': 'DELETE not implemented properly',
                'Count': 0,
                'Result': []
            }

            # Set code
            codeVal = 500

            # Log message
            tfwsclass._setLogger('DELETE ' + str(e))

        # Return dictionary with code
        return returnDict, codeVal
# Import modules
from flask import Flask, request, jsonify  # Flask, request, jsonify
from flask_restful import Api  # flask_restful, api
import json  # json
import tvfeedwebserviceclass  # tv feed web service class
from tvfeedclass import TVFeedClass  # tv feed web service class
from tvfeedtitleshortclass import TVFeedTitleShortClass  # tv feed title short web service class
from tvfeedtitleshortactionstatusclass import TVFeedTitleShortActionStatusClass  # tv feed title short action status web service class

# Create objects
app = Flask(__name__)
api = Api(app)

# Set object
tfwsclass = tvfeedwebserviceclass.TVFeedWebServiceClass()

# try to execute the command(s)
try:
    # Error handler
    @app.errorhandler(Exception)
    def errorHandling(eh):
        # Initialize variables
        messageVal = ''
        codeVal = 500

        # try to execute the command(s)
        try:
            # Set message
            messageVal = str(eh.code) + ' ' + str(eh.name) + ' ' + str(
                eh.description)