1

I am new in python technology, am getting an error while while running my application , don't know where am wrong , please try t fix my error, if you have any question please free feel to ask any time.

Error

newspaper.py

This is my newspaper.py file which file i want to run. My application is running but when i insert link then getting an error

import newspaper
from newspaper import Article
from newspaper import fulltext
import subprocess
import tkinter as tk
from PIL import ImageTk, Image  
import operator    

truncate_ =['on','said','their','there','in','under','between','behind','back','front','of','as','to','besides','before','after','if','because','but','and','an','a','the','is','was','were','had','have','are']

word_count={}
url = input('Enter the URL of the news article: ')
article = Article(url)
article.download()
article.parse()
f= open("article_content.txt","w+")
f.write(article.text)
f.close
f = open("keyword_count.txt","w+")
subprocess.call(['./bda_script.sh'])
article.nlp()
print('-->TITLE: ', article.title)
print('\t****\n')

if len(article.authors)>0:
    print('-->AUTHORS/ PUBLISHER: ',)
    for author in article.authors:
        print(author,'\t',) 
print('\t****\n')

print('-->PUBLISH DATE: ', article.publish_date)
print('\t****\n')

print('-->ARTICLE CONTENT: ', article.text[:250])
print('\t****\n')

if article.summary != '':
    print('-->SUMMARY: ', article.summary)
    print('\t****\n')

if len(article.keywords)>0:
    #print('-->KEYWORDS (NLP Library): ')
    #for keyword in article.keywords:
        #print(keyword,', ',end='')
    #print('\n\t****\n')
 
    print('-->KEYWORDS(NLP Library): ')

f = open("keyword_count.txt", "r")
if len(article.keywords)>0:
    for line in f:
        if line.split()[0][-1].islower == False: 
            word = line.split()[0][:-1]
        else:
            word = line.split()[0]
        if word in article.keywords: 
            print('[',word,', ',line.split()[1],']', end='')
        if word not in truncate_ and len(word)>4:
            word_count[word] = line.split()[1] 
print('\n\t****\n')


    
sorted_keys = sorted(word_count, key=word_count.get, reverse=True)

print('-->KEYWORDS (MAP REDUCE): ')

for r in sorted_keys:
    keywords_ = sorted_keys[:len(article.keywords)]

for w in keywords_:
    print('[',w,', ',word_count[w],']', end='')


print('\n\t****\n')

print ('-->SIMILARITY: ',((len(set(keywords_) & set(article.keywords))/len(article.keywords))*100)+20,'%')
print('\n\t****\n')

print('-->ARTICLE HTML: ', article.html[:250])
print('\n\t****\n')

if article.top_image != '':
    print('-->ARTICLE TOP IMAGE: ', article.top_image)
    print('\n\t****\n')

if len(article.movies)>0:
    print('-->RELEVANT VIDEOS: ')
    for movie in article.movies:
        print(movie,', ',end='')
    print('\n\t****\n')


'''window = tk.Tk()
window.title("TOP IMAGE")
window.geometry("300x300")
window.configure(background='grey')

path = article.top_image

#Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
img = ImageTk.PhotoImage(Image.open(path))

#The Label widget is a standard Tkinter widget used to display a text or image on the screen.
panel = tk.Label(window, image = img)

#The Pack geometry manager packs widgets in rows or columns.
panel.pack(side = "bottom", fill = "both", expand = "yes")

#Start the GUI
window.mainloop()'''

bda_script.sh

#!/bin/sh

cat article_content.txt | ./mapper.py | ./reducer.py | sudo cat > keyword_count.txt 
Monu Patil
  • 345
  • 5
  • 18
  • It looks like you're trying to call a Unix shell script on Windows. – Antimon Oct 23 '21 at 04:29
  • @Antimon can you tell me what is the windows shell script – Monu Patil Oct 23 '21 at 04:31
  • I don't know, because I don't know the contents of the sh script and I also don't know the context of what you're trying to achieve, where this code came from, etc. – Antimon Oct 23 '21 at 04:40
  • @Antimon Why do you think that? `%1` is how a Windows batch file refers to parameters. A Unix script would use `$1`. – Barmar Oct 23 '21 at 04:43
  • Yes, it's how Windows takes its parameters - which in this case seems to be a shell script, which is why the OS complains about that parameter not being a Win32 application. That's my strong suspicion, at least. – Antimon Oct 23 '21 at 04:44
  • #!/bin/sh cat article_content.txt | ./mapper.py | ./reducer.py | sudo cat > keyword_count.txt I have added sh script – Monu Patil Oct 23 '21 at 04:44
  • `bda_script.sh` seems to expect to be given command-line arguments, but you didn't include any when you called it from Python. – Barmar Oct 23 '21 at 04:44
  • @MonuPatil That's a Unix script, not a Windows batch file. It doesn't have `%1`, which is in the error message, so I don't think it's the file you're running. – Barmar Oct 23 '21 at 04:46
  • So can you tell what should i do? – Monu Patil Oct 23 '21 at 04:47
  • Find the actual `bda_script.sh` batch file, and see how it expects to be called. – Barmar Oct 23 '21 at 04:48
  • @Barmar i have added bda_script.sh file you can checkout now and let me know what changes should i do? – Monu Patil Oct 23 '21 at 04:55
  • You need to completely rewrite that script using Windows tools, not Unix commands. – Barmar Oct 23 '21 at 04:58
  • I can't help you with that, I don't do Windows. – Barmar Oct 23 '21 at 04:58
  • Thanks all of you guys , giving your Efforts – Monu Patil Oct 23 '21 at 05:00
  • What are you trying to accomplish using Newspaper3k? I'm asking this question, because I cannot follow the logic in your code. – Life is complex Oct 23 '21 at 17:16
  • Also this [Newspaper3k Overview Document](https://github.com/johnbumgarner/newspaper3_usage_overview) that I wrote might be useful to you. – Life is complex Oct 23 '21 at 17:19

0 Answers0