simple python programs that read files and produce other files with very specific formats.

 A telecommunication company realized that there is a group of 9 customers that had an excessive number of calls among each other in a period of a month exceeding the usual number of calls per day. Assume you were hired to help their investigation team by writing simple python programs that read files and produce other files with very specific formats.
The database team of the telecommunication company provides you with two text files containing a snippet of their data related to this particular group.
The first file customers.txt contains the list of customers with their phone number and the city they are from. The file has in each line a phone number, a customer name and a city separated by “;”. The file content looks like this:
7804922860;Osmar Zaiane;Edmonton
7801234567;Ameneh Gholipour Shahraki;Hinton
7809876543;Farrukh Ahmed;Edson
7803214567;Md Toukir Imam;Sherwood Park
7807890123;Elham Ahmadi;Devon
7808907654;Weifeng Chen;Spruce Grove
7801236789;Stuart Johnson; Saint Albert
7804321098;Hamman Samuel;Stony Plain
7808765432;Amir Hossein Faghih Dinevari;Beaumont
 The second file calls.txt, is a log with the call history for all calls during this particular month period between members of this group. Each line contains a special timestamp, the caller number, the receiver number, the duration of the call in seconds and the rate per minute in cents at which this call was charged, all separated by “;”. The file contains thousands of calls looks like this.
You are tasked to write two programs. The first program is for the accounting department that would like to know what was realized from this group and possibly provide incentives to some good customers, and for this they need a summarizing table report. The second program is for the investigation department to see if there is any scam happening, and for this they need to build a graph of the different calls and do network analysis on it.
Task 1
Write a program in python that reads the two files and produces a table formatted as follows:
| Phone number | Name                         | # |Duration | Due    |
|(780) 123 4567|Ameneh Gholipour Shahraki     |384|55h07m53s|$ 876.97|**
|(780) 123 6789|Stuart Johnson                |132|17h53m19s|$ 288.81|
|(780) 321 4567|Md Toukir Imam                |363|49h52m12s|$ 827.48|++
|(780) 432 1098|Hamman Samuel                 |112|16h05m09s|$ 259.66|
|(780) 492 2860|Osmar Zaiane                  |502|69h27m48s|$1160.52|**
|(780) 789 0123|Elham Ahmadi                  |259|35h56m10s|$ 596.94|
|(780) 876 5432|Amir Hossein Faghih Dinevari  |129|17h22m32s|$ 288.56|
|(780) 890 7654|Weifeng Chen                  |245|33h48m46s|$ 539.41|
|(780) 987 6543|Farrukh Ahmed                 |374|52h50m11s|$ 883.72|**
| Total dues   |                                          $   5722.07|
The table has 5 columns and is sorted on the phone number.
·         The first column is for the phone number. This number has to be formatted as (999) 999 9999.
·         The second column is for the name and it has to be 30 characters wide.
·         The third column is for the number of calls originating from the phone in question. It should be on 3 digits.
·         The fourth column is for the total duration of the calls originating from the phone in question. This duration should be formatted as follows: 99h99m99s for hours, minutes and seconds. The minutes and seconds should have a prefix of 0 if less than 10.
·         The fifth column is for the amount paid for the calls calculated based on the rates attached to each call. Note that the duration for each call should be rounded up to the minute in order to use the rate per minute. This amount should be printed with 7 positions and only 2 after the decimal point.
·         Moreover, the managers would like to have either 2 stars at the end of the row if the amount is higher than $800 or 2 pluses if the amount is not above $850 but the number of calls is superior to 350.
·         Finally, a line at the end of the table should indicate the total amount paid by the whole group. The table should be formatted as illustrated above.
Task 2
Write a program in python that reads the two files and produces a file that can be used by graph visualization tool. The graph visualization tool needs information about nodes in the graph and information about the edges between these nodes. The nodes are the customers identified by their phone numbers and the edges represent a phone called another with a weight for the edge indicating the number of times there was a call or the total duration of the calls between the two phones. A graph can either be directed when the edge shows who called who, or undirected where the edge only shows that a communication happened between two nodes without indicating the initiator and the receiver..
The program also reads from the users two pieces of information: 1- should the graph be directed; 2 is the edge weight the number of calls or the duration of calls. The directed graph means that the edge between two nodes has a direction: from the caller to the receiver.
The program should ask:
Data for:
Directed graph .....1
Undirected graph ...0
for the first question and
Edge weigth is:
The number of calls ...1
The time spent ........0
for the second question. In both cases a validation should be done for the input and accept only either 0 or 1 and keep asking the question until a correct answer is entered.
Your program should output a file callgraph.txt with two parts using the following structure. The two parts are separated by an empty line.
First part: the nodes
Each node is presented in one line as follows: number, phone number, name, city, total time spent; where number is a sequential number starting from 1 that identifies the node. Total time spent is the total number of seconds in calls initiated by the phone number.
Second part: the edges
Each edge is presented in one line as follows: number of origin, number of destination, weight; where number origin and destination are numbers identifying the nodes in the first part of the file.  
An example of the callgraph.txt file could look like this. Note that the nodes are sorted by phone number.
2, 7801234567, Ameneh Gholipour Shahraki, Hinton, 198473
7, 7801236789, Stuart Johnson, Saint Albert, 64399
4, 7803214567, Md Toukir Imam, Sherwood Park, 179532
8, 7804321098, Hamman Samuel, Stony Plain, 57909
1, 7804922860, Osmar Zaiane, Edmonton, 250068
5, 7807890123, Elham Ahmadi, Devon, 129370
9, 7808765432, Amir Hossein Faghih Dinevari, Beaumont, 62552
6, 7808907654, Weifeng Chen, Spruce Grove, 121726
3, 7809876543, Farrukh Ahmed, Edson, 190211
2, 7, 40425
2, 4, 21618
2, 8, 34186
2, 1, 34291
2, 5, 24286
2, 9, 67786
2, 6, 21983
2, 3, 35614
7, 4, 32851
7, 8, 27293
7, 1, 45367
Powered by