File size: 1,014 Bytes
bd149ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
08072ed
 
 
 
 
 
 
 
 
 
 
946e905
 
 
 
 
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
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from fastapi import FastAPI
import json

app = FastAPI()

app.add_middleware(CORSMiddleware, allow_origins = ['*'], allow_credentials = True, allow_methods = ['*'], allow_headers = ['*'])

@app.get('/')
def index():
    
    return JSONResponse(status_code = 200, content = {'status' : 'online'})

@app.get('/read')
def read_route():
    
    with open('cookies.json', 'r', encoding = 'utf-8') as file:
        
        data = json.load(file)
        
    return JSONResponse(status_code = 200, content = data)

@app.get('/write/{number}')
def read_route(number: int):
    
    with open('cookies.json', 'r', encoding = 'utf-8') as file:
        
        data = json.load(file)
        
    data['deneme'] = number
    
    with open('cookies.json', 'w', encoding = 'utf-8') as file:
        
        json.dump(data, file, ensure_ascii = False, indent = 4)
    
    return JSONResponse(status_code = 200, content = 'ok')