Those constants (
macron,equalSign,underscore) are a bit uselessly named. It's no use havingconst int TEN = 10const int TEN = 10; use names that reflect what the constants are for. (This also helps avoid the analogic case ofconst int TEN = 11when you need to change the constant in a new version...) Better yet, put the constants into predicate functions that encapsulate all the checking in one easy-to-use package.The nested loops over your file handle may work, but they're confusing as heck. I recommend an outer
while Trueloop and manual calls tof.next().Your code is very nested. Try splitting it into multiple functions.
It's often preferable to return early (
if not tempList: break) instead of nesting (if tempList: ...).Your inner loop could be improved to handle an entire "record" (begin day, stuff happens, end day) at a time, rather than taking each line and clumsily maintaining state. (All this really entails is changing the structure to remove the loops and clearly define a sequence of processing; moving the code into its own function is just bonus points.)
Some bits of code common to all branches of execution (
d.month_year(month_year)is one spot,d.activity_name(tempList[0])is another) can be moved out of the branching constructs.If a day is started without ending the previous day, the code throws the previous day away. You might want to change that.
You're not awfully clear about whether the macron to start a new day gets its own line; your code acts as if it does (by throwing away the rest of that line), so I'm going with that.
Your terminating characters (macron, equals, underscore) - you say they have to be at the beginning of the line, but then test if they're anywhere in the line! Combined with the above leap of logic, you can simplify those tests to checking if the character is the only one on its line.
Other-activity sections (terminated with
_) don't terminate a record when they end. I'l assume it's impermissible to have anything between the end of an other-section and the end of the record.
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/