Skip to content

Commit

Permalink
Merge pull request #6 from schemen/devel
Browse files Browse the repository at this point in the history
Add much needed -lm/--list-manga feature
  • Loading branch information
schemen authored Nov 25, 2017
2 parents a6fbea0 + 69d7674 commit 5391a4e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 4 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ Example:

### Help output:
```
usage: m2em.py [-h] [-af ADD_FEED] [-au] [-lc] [-Lc] [-lf] [-lu] [-cd] [-s]
[--send [SEND [SEND ...]]] [--convert [CONVERT [CONVERT ...]]]
usage: m2em.py [-h] [-af ADD_FEED] [-au] [-lm [LIST_MANGA]] [-lc] [-Lc] [-lf]
[-lu] [-cd] [-s] [--send [SEND [SEND ...]]]
[--convert [CONVERT [CONVERT ...]]]
[--download [DOWNLOAD [DOWNLOAD ...]]] [-a ACTION]
[-ss SWITCH_SEND] [-sc SWITCH_CHAPTER] [-dc DELETE_CHAPTER]
[-du DELETE_USER] [-df DELETE_FEED] [--daemon] [-d] [-v]
Expand All @@ -92,6 +93,9 @@ optional arguments:
Add RSS Feed of Manga. Only Mangastream & MangaFox are
supported
-au, --add-user Adds new user
-lm [LIST_MANGA], --list-manga [LIST_MANGA]
Lists Manga saved in database. If a Manga is passed,
lists chapters to said Manga
-lc, --list-chapters Lists the last 10 Chapters
-Lc, --list-chapters-all
Lists all Chapters
Expand Down Expand Up @@ -162,6 +166,25 @@ EmailAdressPw = yourpassword
ServerStartSSL = True
```

## Examples

If you want to check out the manga that are in the database:
```
./m2em.py -lm
```
You can use this out put to refine the search!
If you pass the manga name you get all chapters listed from that manga:
```
./m2em.py -lm "Shokugeki no Souma"
Listing all chapters of Shokugeki no Souma:
ID MANGA CHAPTER CHAPTERNAME RSS ORIGIN SEND STATUS
===================================================================================================
112 Shokugeki no Souma 240 Not Cute https://mangastream.com/rss SENT
91 Shokugeki no Souma 238 The Queen's Tart https://mangastream.com/rss SENT
78 Shokugeki no Souma 239 Her Fighting Style https://mangastream.com/rss SENT
```


To start a single run through the workers, you can simply execute the main program:
Expand Down
2 changes: 1 addition & 1 deletion bin/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "v0.3.0"
__version__ = "v0.3.1"
68 changes: 67 additions & 1 deletion bin/m2emHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,4 +938,70 @@ def initialize_logger(output_dir, outputlevel):
handler.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s; %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.addHandler(handler)



'''
Function that gets feed data and display it nicely
Returns: N/A
'''
def printManga(config, args):


# Get database config
database = config["Database"]

# Open Database
try:
conn = sqlite3.connect(database)
except Exception as e:
print("Could not connect to DB %s" % e)

c = conn.cursor()
logging.debug("Succesfully Connected to DB %s" % database)



if args.list_manga == "all":
# Get Data
__data = c.execute("SELECT manganame FROM chapter")
__tabledata = set(__data.fetchall())


if __tabledata:
logging.info("Mangas with chapters in the database:")
for i in __tabledata:
logging.info("* %s"% i)
else:
__data = c.execute("SELECT * FROM chapter where manganame=(?)", (args.list_manga,))
__tabledata = __data.fetchall()

if len(__tabledata) == 0:
logging.error("No Manga with that Name found!")
else:
# Reverse List to get newest first
__tabledata.reverse()

table = texttable.Texttable(max_width=120)
table.set_deco(texttable.Texttable.HEADER)
table.set_cols_align(["l", "l", "l", "l", "l", "l"])
table.set_cols_dtype(['i', # int
't',
't',
't',
't',
't']) # text
table.header (["ID", "MANGA", "CHAPTER", "CHAPTERNAME", "RSS ORIGIN", "SEND STATUS"])


logging.info("Listing all chapters of %s:"% args.list_manga)
for row in __tabledata:
# Rename row[8]
if row[8] == 1:
sendstatus = "SENT"
else:
sendstatus = "NOT SENT"
table.add_row([row[0], row[11], row[10], row[5]+"\n", str(row[1]), sendstatus])
logging.info(table.draw())

17 changes: 17 additions & 0 deletions m2em.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def read_arguments(self):
parser.add_argument("-af", "--add-feed", help="Add RSS Feed of Manga. Only Mangastream & MangaFox are supported")
parser.add_argument("-au", "--add-user", help="Adds new user",
action="store_true")
parser.add_argument("-lm", "--list-manga", help="Lists Manga saved in database. If a Manga is passed, lists chapters to said Manga",nargs="?",const='all')
parser.add_argument("-lc", "--list-chapters", help="Lists the last 10 Chapters",
action="store_true")
parser.add_argument("-Lc", "--list-chapters-all", help="Lists all Chapters",
Expand Down Expand Up @@ -95,6 +96,7 @@ def read_arguments(self):
and self.args.switch_chapter is None \
and self.args.switch_send is None \
and self.args.add_user is False \
and self.args.list_manga is None \
and not any([self.args.add_user,
self.args.create_db,
self.args.daemon,
Expand All @@ -107,6 +109,8 @@ def read_arguments(self):
self.args.send,
self.args.start,]):
logging.error("At least one argument is required!")

logging.debug("Passed arguments: \n %s"% self.args)

#Read Config
def read_config(self):
Expand Down Expand Up @@ -189,6 +193,15 @@ def list_chapters(self):
pass


'''
Catch -lm/--list-manga
'''
def list_manga(self):
helper.printManga(self.config,self.args)
pass



'''
Catch --list-users
'''
Expand Down Expand Up @@ -312,6 +325,10 @@ def run(self):
self.list_chapters()
return

if self.args.list_manga:
self.list_manga()
return

if self.args.add_user:
self.add_user()
return
Expand Down

0 comments on commit 5391a4e

Please sign in to comment.