enigmaiitd / CampusHack

Library Portal to show currently issued books from IITD Library
1 stars 0 forks source link

Add a Parser Class to fetch all the necesaary information from email text #1

Closed tmibvishal closed 5 years ago

tmibvishal commented 5 years ago

Add a Parser Class that will fetch all the necessary information from the email text like book name and due date etc.

arpit-saxena commented 5 years ago

Am currently working on it.

vishalBindal commented 5 years ago

Added separate functions (for issue and return) to return data for books. (Return an array of BookInfo objects) .

I have considered formatting we see on opening the mails in iitd intranet. I have considered a newline character will be present at the end of each line after converting the message to a string.

The workflow (for the function handling issue of books) is as follows:

  1. The string is first split based on the newline character
  2. The occurence of word "ISSUE" is searched in a line. Let this line be i.
  3. The name and entry no of the person issued to will be present in the nearest non-empty line(i+1 or i+2). This line is taken, trimmed and split on basis of '(' or ')'. Name and entry no are stored.
  4. The occurence of word "S NO" is searched in a line. Let this line be k.
  5. The no of books are calculated. For each book steps(6-9) are performed.
  6. The accNo,name of book(may be incomplete), date is written in the nearest non-empty line(k+1 or k+2) . All three values are stored in string format in similar fashion as above.
  7. If the book name takes more than one line(let first line be a): The book name in second line(let a+1) will be written after a certain no of spaces. The no of whitespaces in line a+1 are calculated and compared to no of characters before name of book in line a. If they are similar name of book is appended. This will be repeated for a+2,a+3,... lines till we get an empty line or no of spaces are different.
  8. Only one thing remains which is to convert date from String to Date format.
  9. All 4 values are used to create a bookInfo object. 10.The array containing bookInfo objects is returned.

The workflow for other function is similar with minimalistic changes.