I have created a program that records my input through the python command line,
it asks for ie, name, favourite food, (they are examples only)
it than writes the inputs to a text file, and calls the text file by one of the inputs (eg, name)

i now want it so the program so whenever i run the program, it adds all the inputs to the same text file, that is named "records" or something like that.

once that has done, i want it to give my program a GUI, giving me lines to enter the data, and than i can click "save" it will write it to the text file names "records"
i also need it to be able to retrieve the records to be displayed on the GUI.

these tasks, i am not familiar with,
i would be extremely appreciative for some pointers, or if somone wants to email me, i will gladly email you the program, so you can see what i'm on about.

i am creating this software for a friend, as he is trying to come up with a solution to manage is out of hours jobs

cheers.

Hello!

If I would have this problem to solve I would do the following.

  1. Identify the data to be stored
  2. Identify the processing workflows
  3. Identify the other-future-unspoken requierements
  4. Design logically
  5. Find best tool to make the job done
  6. Design tool specific code

It is the ideal setting. We have here python as the tool, to make the job done. I think it will work.

1. Data to be stored:
Let the data be:

  • text of the record

2. Processing workflow
User enters the text. The entered data is stored permanently.
User queries all the stored records. Looks at the text, nothing more.

3. Other requierements
The system is able to provide console and GUI user interface. The interface change should not change the underlying code

4. Design logically
In ideal situation I go through 1-3 and make changes. For example in 2, I see the user wants to query the last 10 or last day entry, not all, and edit it. So I must change the data structure to provide a sequential id and a timestamp. And so on.

5. Best tool
Well, we have python, no choice.
For console interface: raw_input-print, cmd module
For GUI interface: qt,wx,tkinter.
for data storage: slqite, text file


6. Design code
Well, based on the requirements:
3 tier MVC design. Data access layer, controller, UI. That makes changing UI and changing database layer easy. However the controller layer is sensitive against changing.

Without further thinking a (nonworking) skeleton follows. Based on it I can repeat the previous steps, to refine (or rewrite) the system, and stabilize the code.

class Data(object):

  def __init__(self,text):
    self._text=text

class FileDataManager(object):
  #FIXME handle flush, exceptions etc...
  def __init__(self,desc):
    self._file=open(desc,"w+")
  def put_data(self,data): pass
  def query_data(self):pass
  def close(self): pass

  
class Controller(object):
  #FIXME handle exceptions  
  def __init__(self, descriptor):
    #TODO later choose datamanager based on descriptor  
    self._manager=FileDataManager(descriptor)
    #TODO later handle configfile

  def put_data(self,data): 
    #FIXME check validity
    self._manager.put_data(data)

  def query_data(self): 
    return self._manager.query_data()
    
  def close(self):
    self._manager.close()

    
class ConsoleUi:

  def start(self):
    self.co=Controller("dtb descriptor")
    self.main()

  def main(self):
    while True:
      #FIXME handle exceptions      
      choice=raw_input("Store?, Query? , Exit? (s/q/x")
      if choice=="x": 
        break
      if choice=="s":
        txt=get_input()
        self.co.put_data(Data(txt)) # FIXME error handling
      if choice=="q":
        data=self.co.query_data()
        self.display_query(data)
    self.co.close()

  def get_input(self):
    return raw_input("what to store?: ")
    
  def put_query(self,data):
    for item in data:
      print item #FIXME rendering of datapieces
    
if __name__=="__main__"
  ui=ConsoleUi()
  ui.start()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.