import feedparser
from optparse import OptionParser
from configparser import ConfigParser
def main ( config ) :
feed = feedparser . parse ( config . get ( ' locations ' , ' feed ' ) )
# print(len(feed.entries))
# print(feed.entries[0].link)
with open ( config . get ( ' locations ' , ' output ' ) , ' r ' ) as file :
lines = [ line . rstrip ( ) for line in file ]
# print(lines)
newworks = 0
with open ( config . get ( ' locations ' , ' output ' ) , ' a ' ) as f : #input=/config/fanfiction_file #output=/output/fanfiction_file
#/Users/sam/Desktop/workspace/FFFRssLinkGrabber/root/config.default/fanfiction_file
for entry in feed . entries :
if entry . link . replace ( ' https:// ' , ' ' ) not in lines :
newworks + = 1
f . write ( f " { entry . link . replace ( ' https:// ' , ' ' ) } \n " )
print ( f " Added { newworks } works out of { len ( feed . entries ) } works to list. " )
if __name__ == " __main__ " :
option_parser = OptionParser ( usage = " usage: % prog [flags] " )
option_parser . add_option (
' -c ' ,
' --config ' ,
action = ' store ' ,
dest = ' config ' ,
help = ' Config file for inputs. Blank config file is provided. No default. If an option is present in whatever config file is passed it, the option will overwrite whatever is passed in through command line arguments unless the option is blank. Do not put any quotation marks in the options. ' )
( options , args ) = option_parser . parse_args ( )
if options . config :
config = ConfigParser ( allow_no_value = True )
config . read ( options . config )
main ( config )