File size: 433 Bytes
29cdc9d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

import json
import os

class StateEngine:
    def __init__(self, file='data.json'):
        self.file = file
    
    def run(self):
        count = 0
        if os.path.exists(self.file):
            with open(self.file, 'r') as f:
                count = json.load(f).get('count', 0)
        
        count += 1
        with open(self.file, 'w') as f:
            json.dump({'count': count}, f)
        return f"Count is {count}"