File size: 4,346 Bytes
2492cab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from flask import Flask, request, jsonify, abort
import tsadropboxretrieval
import pdftotext
import requests
app = Flask(__name__)

@app.route("/",methods=["GET", "POST"])
def thismain():
    print('ayhaga')
    return jsonify('done')
    
@app.route('/api/process-data', methods=['POST'])
def processtobegin():
    # check_api_key()
    try:
        
        print('In process [Try]')
        # data = request.form
        data = request.get_json()
        # Extracting values
        filePath = data.get('filePath')
        groupName = data.get('groupName')
        print(filePath,groupName)
        pdftext = pdftotext.texts_from_pdf(filePath,groupName)
        return jsonify(pdftext)
    
    except Exception as e:
        print(f"Error: {e}")
        return jsonify({"error": str(e)}), 500


@app.route("/apiMC",methods=["GET", "POST"])
def apifunction():
    try:
        print('In process [Try]')
        # data = request.form
        data = request.get_json()
        print('here',data)
        # Extracting values
        if data:
            # Pass the raw JSON data to the filtering function
            jsonOutput = pdftotext.apiFiltering(data)
            return jsonify(jsonOutput)


    
    except Exception as e:
        print(f"Error: {e}")
        return jsonify({"error": str(e)}), 500
        
@app.route('/botTest', methods=['POST'])
def processrawan():
    try:
        query={'loginname':'Marthe','password':'marthemain'}
        #token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiQURSIiwibmJmIjoiMTY4MDg1OTgzMyIsImV4cCI6IjE2ODA5MDMwMzMifQ.-FULhKD_M-cyIdSMMIYDlEo9DoZtc00yIlyXIPuyLZI"
        head={'Content-Type':'application/json'}
        response=requests.post(url="https://console.trevorsadd.co.uk/account/login",json=query,headers=head,verify=False)
        key=response.text
        
        head={'Content-Type':'application/json;charset=UTF-8',"Authorization":'Bearer {}'.format(key)}
        response=requests.post(url="https://console.trevorsadd.co.uk/project/getprojectslist",json=query,headers=head,verify=False)
        dict1=response.json()
        print('dict',dict1)
        print('In process [Try]')
        data = request.get_json()
        # Extracting values
        conversationId = data.get('conversationId')
        print(conversationId)
        # groupName = data.get('groupName')
        print(data)
        return jsonify({
            'conversationId': conversationId,
            'MC_data':dict1
        })
    except Exception as e:
        print(f"Error: {e}")
        return jsonify({"error": str(e)}), 500


@app.route('/processalltext1', methods=['POST'])
def processalltextTotext():
    # check_api_key()
    try:
        print('In process')
        data = request.get_json()  # Correct method to get JSON data
        print(data)
             
        # Ensure 'pdfpath' is included in the request
        if 'filePath' not in data:
            return jsonify({"error": "Missing 'pdfpath' in request data"}), 400
        
        pdfpath = data['filePath']
        
        # dbxTeam = tsadropboxretrieval.ADR_Access_DropboxTeam('user')
        # md, res = dbxTeam.files_download(path=pdfpath)
        # pdf_data = res.content
        
        # Ensure 'pdftotext.texts_from_pdf' is a valid function
        pdftext = pdftotext.texts_from_pdfAllText(pdfpath)
        
        # Prepare response
        response_data = {
            "message": "Data received",
            "input_data": pdftext
        }
        return jsonify(response_data)
    
    except Exception as e:
        print(f"Error: {e}")
        return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)


# from flask import Flask, request, jsonify

# app = Flask(__name__)

# @app.route('/api/process-data', methods=['POST'])
# def process_data():
#     # Get JSON data from the request
#     data = request.get_json()

#     # Perform some processing on the data
#     # For example, let's just return the data back with a message
#     processed_data = {
#         'message': 'Data received and processed successfully!',
#         'received_data': data
#     } 
     
#     return jsonify(processed_data)

# if __name__ == '__main__':
#     app.run(host='0.0.0.0', port=7860, debug=True)