• Breaking News

    Tuesday, April 7, 2020

    That "keep it simple, idiot" saying is saving me from a lot of trouble lately. What are some other good sayings? Ask Programming

    That "keep it simple, idiot" saying is saving me from a lot of trouble lately. What are some other good sayings? Ask Programming


    That "keep it simple, idiot" saying is saving me from a lot of trouble lately. What are some other good sayings?

    Posted: 07 Apr 2020 11:14 AM PDT

    I was just trying to to several things in a function and breaking my head over the 4d chess that I have to keep track of.. and I was stressed.. and at one point I was like: I don'th ave time for this shit.. the function is called "do x".. not "do x, y and z"... so I deleted half the function and now everything is nice and trim and logical and the data is actually more readable than before.. and the functions for y and z will be one-liners...

    So yea.. any other kind of advice for a newbie?

    submitted by /u/asssed
    [link] [comments]

    Should a DigitalOcean VM be 85% slower than a 2017 MacBook Pro for pgbench?

    Posted: 07 Apr 2020 07:15 PM PDT

    DigitalOcean droplet:

    $20/mo, 2 vCPU, 4 GB memory, 80 GB SSD (Intel Xeon CPU E5-2650L v3 @ 1.80GHz)

    Local machine:

    MacBook Pro (13-inch, 2017), 3.1 GHz Dual-Core Intel Core i5, 16GB memory, SSD

    init command: pgbench -i -d postgres

    Bench command: pgbench -c 10 -T 60 postgres (10 clients for 60 seconds)

    results (digitalocean):

    starting vacuum...end. transaction type: <builtin: TPC-B (sort of)> scaling factor: 1 query mode: simple number of clients: 10 number of threads: 1 duration: 60 s number of transactions actually processed: 21333 latency average = 28.147 ms tps = 355.280880 (including connections establishing) tps = 355.321242 (excluding connections establishing) 

    results (mac os x):

    starting vacuum...end. transaction type: <builtin: TPC-B (sort of)> scaling factor: 1 query mode: simple number of clients: 10 number of threads: 1 duration: 60 s number of transactions actually processed: 151292 latency average = 3.966 ms tps = 2521.214990 (including connections establishing) tps = 2521.357049 (excluding connections establishing) 

    both latest postgres 12.2

    2521tps vs 355tps is 85% slower

    if i run postgres in docker on digitalocean with a bind mount with this command:

    docker run --rm \ --name postgresql \ -e POSTGRES_PASSWORD=postgres \ -d \ -p 5432:5432 \ --mount type=bind,source=$HOME/docker/volumes/postgres,target=/var/lib/postgresql/data \ postgres:12.2 

    performance is 33% worse. 355tps native, 236tps docker

    starting vacuum...end. transaction type: <builtin: TPC-B (sort of)> scaling factor: 1 query mode: simple number of clients: 10 number of threads: 1 duration: 60 s number of transactions actually processed: 14181 latency average = 42.333 ms tps = 236.223887 (including connections establishing) tps = 236.248415 (excluding connections establishing) 
    submitted by /u/waltwhitman83
    [link] [comments]

    Variable naming?

    Posted: 07 Apr 2020 09:33 PM PDT

    I got still confuse about this variable naming. I had a code review and submitted it. Got rejected because of the variable naming. Consider the following.

    val isCollectionEmpty() -> my variable name

    val isEmptyCollection() -> the senior dev's variable name

    Both have the same meaning and is clear. I just don't understand the difference. I could convert this name to a question

    1. isCollectionEmpty() -> is the collection empty? -> sounds right
    2. isEmptyCollection() -> is Empty Collection? -> sounds not right.

    I don't know. It just confusing. Just out of curiosity which one makes sense? English is not my native language and I am not sure which one should be the correct one.

    submitted by /u/learnig_noob
    [link] [comments]

    250 microservices and I have no idea what any of them do.

    Posted: 07 Apr 2020 04:36 PM PDT

    Hey! With the trend of micro-services becoming really popular over the last few years, I've noticed that it's also getting harder to know what system does what. Example that I just made up, probably not how Tinder is built

    It's especially difficult for new starts to figure out what the infrastructure as a whole looks like. But this problem is also true for people who have been in the company for a while. As, hopefully, things are constantly evolving and systems and popping up and down weekly.

    I'm developing something that aims to be the single source of truth for companies that run micro-services. Something a bit more purpose built and powerful than Visio or other diagram tools. Potentially partially automated with minimal upkeep from the devs.

    Is this a problem you have at work? Would this be helpful for you?

    submitted by /u/the_other_JFK
    [link] [comments]

    which of the following is not a character constant in C?

    Posted: 07 Apr 2020 04:30 PM PDT

    a. 'c'

    b. 'bb'

    c. "C"

    d. '?'

    e. ' '

    I am confused ,whether answer is option b or option c .

    Can you help me out with this?

    submitted by /u/sujalgupta6100
    [link] [comments]

    TikTok and other social media languages

    Posted: 07 Apr 2020 08:09 PM PDT

    What are social media applications like TikTok written in? From front end user interactions, to backend data handling, to storing information in databases. What is the full cycle of all of this including languages? Thanks!

    submitted by /u/creehiker16
    [link] [comments]

    -Linux- how do I give a class permissions to write, but not to delete? Does the affect the chmod octal #?

    Posted: 07 Apr 2020 06:48 PM PDT

    Currently trying to set permissions as:

    Owner: Read/write/execute

    Group: Read/write/execute

    other: Read/write/execute

    I understand the chmod # is 777, however is there some way to prevent the "other" class from being able to delete? And would this change the chmod #? And if it does what is the #?

    submitted by /u/notcode6charles
    [link] [comments]

    Looking for Guidance/Ideas for Graduation Project

    Posted: 07 Apr 2020 02:09 PM PDT

    Theme: Collaborative Work.

    Platform: Linux.

    Languages: Java, Python, C++. (Intermediate)

    Time Frame: ~90 days.

    I was thinking about implementing a Git like command line application, but I got overwhelmed :/ , I'm not sure where to start. Sources I found on the internet seemed a bit complicated and there is not much talking about the design nor the concept behind, they're mostly about implementations and functionality (or so it seems to me). I tried looking at the source code, but I takes time to understand how things are lied out, as most of it is fine tuned and optimized.

    So I thought you guys could help, maybe give me some pointers on where to start on this project, or maybe give other ideas that are doable in that time frame.

    Thank you! :)

    submitted by /u/mckodi
    [link] [comments]

    python wont open a window but isn't giving me any errors

    Posted: 07 Apr 2020 02:46 AM PDT

    I am a beginner using python 3.8 on a mac. the folowing code is supposed to open a new window but is not doing so. Problem is, I am not getting any errors. Any ideas?

    import sys import pygame from settings import Settings from ship import Ship def run_game(): #initialize pygame settings and screen object pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Alien Invasion") #make a ship ship = Ship(screen) bg_color = (230, 230, 230) #start the main loop for the game. while True: #watch for keyboard and mouse events. for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() #redraw the screen during each pass through the loop. screen.fill(ai_settings.bg_color) ship.blitme() #make the most recently drawn screen visible. pygame.display.flip() run_game() 

    Edit: after a very frustrating 2 days of trial and error. I deleted python 3.8 and downloaded 3.7. when I ran the code it worked, I have no idea why but I am celebrating nonetheless. Thanks for everyones's help!

    submitted by /u/mandem-and-moves
    [link] [comments]

    This is a silly question coming from someone who has as much experience with programming as a 9 year old, addicted to scratch.mit.edu.

    Posted: 07 Apr 2020 05:06 PM PDT

    How much programming knowledge(experience, languiges, whatever) would one need to know in order to create a program in which there would be a 3 dimensional game? I'll explain further: The idea is a "game" of sorts, more of an artistic demonstration.

    * I want a player character who can walk around, and look at generated objects.

    *I also want to add in a function that observes a user's eye track; showing the computer where the user is looking,

    * and then I would want to cover the screen with black, but only in the bottom right hand corner of the screen, depending on the user eyetrack.

    * The black area would grow bigger following the eye track if the user looked up and to the left, and it would shrink if the user looked further down and to the right

    (This would be the main point of the game, to show people what a field cut or damaged peripheral vision is like. I have that, I just described basically what my vision is like)

    Look, I know this is probably a HUGE undertaking and I would need to learn a lot of basic fundamentals to make this program. I would just like to humbly ask the users of r/AskProgramming, Be honest. How would a beginner like me get started, and how long would it take for me to learn how to make this, and how long would it take to create this program? I know programming is very complected for a novice, I am willing to learn and work on this for many years :)

    submitted by /u/nokillsdishonered1
    [link] [comments]

    Social Network Application

    Posted: 07 Apr 2020 04:45 PM PDT

    Hey guys, I am attempting to build a social networking application. I am a third year computer science student with some front end experience and much more back end experience. Does anyone have any advice on online tools that can help me get started? I am struggling with things as simple as how to store things like followers. Does this go into a database or a list stored in a user class? Any advice is appreciated.

    submitted by /u/creehiker16
    [link] [comments]

    A Better IDE for Learning C/C++ Programming

    Posted: 07 Apr 2020 04:36 PM PDT

    Recommend Me a Language: I Like Ruby and Haskell

    Posted: 07 Apr 2020 04:10 PM PDT

    (This is my first time posting. I hope that this is the right place to ask.)

    I am a CS student that really enjoys coding in Ruby and Haskell.

    I am still taking classes either way, so this is for personal enjoyment. I want to know now what languages might provide a similar coding experience so that I don't miss out on them when I decide to learn a new hobby language over the summer, or something.

    I believe I enjoy Ruby and Haskell because of their flexible syntax and vocabulary. Human languages provide dozens of ways to express things and our mind seems to prefer bouncing around looking for words that just might work, rather than keeping it simple. Having a programming language work a bit like this felt great (even if it's not conducive to the best codebase). Maybe I prefer TMTOWTDI?

    Here is my request: Recommend me a language (or framework or anything) that provide a similar coding experience to the above.

    Some questions & ideas:

    1. I've read Javascript is also similarly flexible. Do you think the experience would be similar?
    2. I've read Elixir was also a programmer friendly language. Do you think it fits the bill?
    3. I'm interested in Perl, but I know so little about it. (1) Is it accessible to someone who's relatively new to development? (2) Is there a lot of material for it? (3) Do you think I would enjoy it?
    4. Is Rust anything like this? My biggest worry is that someone who has trouble wrapping his head around how servers work, what an API is, et cetera would be in over his head with Rust.

    Some information:

    1. Working through beginner tutorials for Go and Elm wasn't fun, although I think these languages are extremely cool, even from a beginner's perspective. I didn't love Java.
    2. Having a great book or course can also make the learning experience extremely pleasant. If there is a - this one is different from all the rest - type of book or course to go along with the language, please include them in the recommendation.
    3. I works as a translator and writing Java felt more like translating a document for a manual or pamphlet and writing Ruby felt more like writing or localizing. Haskell felt a bit like hand-scribbled math which can be very flexible and fun. (I liked math and English in school.)

    If I missed any obvious or crucial information, I apologize and feel free to chime in with something if it seems at all relevant or you'd like to pass on some knowledge to a newbie!

    submitted by /u/Outside_College
    [link] [comments]

    Do people actually pronounce “SQL” as “Sequel” in the real world?

    Posted: 07 Apr 2020 10:29 AM PDT

    I'm taking an entry level programming class and my professor claims that people call it sequel, is it true?

    submitted by /u/KTthemajicgoat
    [link] [comments]

    Parallel Processing Excel Sheet Data

    Posted: 07 Apr 2020 01:43 PM PDT

    Not sure how I would go about this, but I have an excel sheet with about 170,000 rows of URLs. I need to open each URL and search for a keyword within the page. The way I have gone about this before is just splitting the excel rows into 4 different excel docs and then running my program searching each URL on 4 different computers. With the coronavirus in full swing I no longer have access to 4 extra computers via work, so I'm just leaving my work computer running for about a week-ish processing the excel sheet line by line.

    So, is there a way to set up my program such that I can split the processing of the excel sheet so that chunks of the sheet are being processed at the same time on the same computer without completely destroying my memory? Any parallel processing methods or packages that can do this? Any other techniques I haven't even thought of?

    submitted by /u/ninjadude93
    [link] [comments]

    How Would I Create Something Like Oracle VM VirtualBox?

    Posted: 07 Apr 2020 08:54 AM PDT

    Hello!

    I'm looking to research, understand, and develop something like a lightweight virtual box where I can boot up images of virtual machines. I do not where to go exactly to learn stuff like this in my free time, since I have a project for my Operating Systems course in University, and it's something that I think I would like to learn as well.

    Any tips and guidance? I do know of osdev.org ! Anything else?

    Thank you!

    EDIT: I'm aware it maybe OS dependent, and pretty sure there are portability issues. As far as I'm concerned, I'm currently an Arch Linux user, so I just want to make something for Linux that can boot up and start Virtual Machines.

    submitted by /u/Are_We_There_Yet256
    [link] [comments]

    How should a project file structure look like?

    Posted: 07 Apr 2020 12:21 PM PDT

    Color Tile Game

    The above link takes you to a color game which I had created ila few years ago, the idea is to select the color that will be formed when three colors RED, GREEN and BLUE are mixed in certain percentage. It was made with basic html, css and js website hosted in GitHub itself.

    Recently, I was super bored doing react and angular and due to lockdown I had plenty of time. So I decided to rewrite everything from scratch using ES6 and adding a few features like login for my friends so that we can store our past gameplays, also a leaderboard to keep track of who is doing better.

    To my surprise, a small project like this is super easy to make without any frameworks and I enjoyed Coding something where I understood everything and there wasn't any magic happening 🤩

    It took me almost 4 days(3hr/day) to complete the project. The current implementation is much more better than previous one, the codebase is readable, modular and neat. I have also worked on the UI to make is more user friendly by using flat colors.

    If anyone is into front-end development I love to hear your feedback on this app.

    Repo link: Github

    If you like the repo, do let me know by 🌟 ing it 🤓

    Note: you don't have to login, that's for my friends only ✨

    submitted by /u/raj_chandra3
    [link] [comments]

    Tags for Moving Video

    Posted: 07 Apr 2020 12:21 PM PDT

    Hi,

    I am trying to replicate a pointer or even a tag that would exist in correlation to moving video. For example, you have three or four blocks that revolve around a circle.

    These blocks go around and yet they do change order. I would like at the top to show a pointer of the order.

    I would want to tag those blocks, and at top show the order. Is this possible for any sort of video - including live?

    Secondly, I would want to change the tags via an interface. Blue Block-Red Block-etc.

    THANKS!!

    submitted by /u/Lokesociete
    [link] [comments]

    What exactly is meant by a programming language being cross-platform?

    Posted: 07 Apr 2020 12:20 PM PDT

    I see this term in descriptions of different programming languages, but I can't seem to figure out what it means.

    submitted by /u/onlysane1
    [link] [comments]

    How to create a Linter: Need some help.

    Posted: 07 Apr 2020 06:52 AM PDT

    Hey guys, im kinda at a loss.

    For a programming project i have to create a Linter for some obscure software, because its only used by a few people around the world and my department hates the code it spews out, they thought it would be nice to give me the task to create a linter for it.

    My problem is mostly that i know how lexer, parser and compilers in general work, not in depth but enough to understand how the rules, tokenization and such work. I also read enough about Linters to know what they do, atleast theoretically. And i know some about regular expression, pattern matching and basically how to find stuff in strings/files.

    With all of that i feel like i should know how to create a Linter, but i feel like i cant fit the pieces together.

    Worst of all, i just cant find a single clear explanation of HOW a Linter is build or actually works internally, there are just millions of sources explaining how to create Linting RULES in some linters like PyLint, ESLint, AndroidLint etc. but nothing like a simple or structured explanation of how to actually do it yourself and not just create rules in a Linter software.

    I have access to the software that i have to create the linter for, which uses XML, the Parser Library for that specific software is mostly in C++, which is also what my Linter would have to be written in.

    Does anyone know enough about Linting or Linter creation to point me to some books, webpages or anything that might help me with this? Ill take anything i can get, since i have to start soon and at this point, my Linter would mostly resort to regular expressions or just pattern matching and i already know this will most likely end in a shitshow since it doesnt seem to be the most efficient or useful way to do it.

    I feel like this shouldnt be too hard but maybe im just too dense to get it.

    I appreciate any help you can offer :)

    submitted by /u/Yaaxil
    [link] [comments]

    How do I get my histogram to plot data differently (in pyplot)?

    Posted: 07 Apr 2020 09:48 AM PDT

    So I've written some code that live streams tweets from Twitter's API based on a searched for hashtag and performs sentiment analysis on them designating each tweet as: positive, wpositive, spositive, negative, wnegative, snegative or neutral. I'm trying to plot a histogram of this data and am having issues.

    Currently my x-axis is the frequency of the sentiment and the y-axis just goes to 1. I want my y-axis to be the frequency of the sentiment and the x-axis to be the type of sentiment (e.g. wpositive, neutral, etc.) but can't figure out how to do it. I've looked at a few posts on Stack Overflow but the posts I find are all numeric based rather than trying to plot strings as an axis.

    I'll post the whole code so you can see what it's doing, the histogram code is blown up near the bottom. Any help with this would be greatly appreciated!

    import csv import re import sys import tweepy import matplotlib.pyplot as plt from textblob import TextBlob import sqlite3 as lite # import models.py - was a file with CREATE statement in for SQLite global db global cursor class SentimentAnalysis: def __init__(self): self.tweets = [] # initialising empty list objects self.tweetText = [] # self.api = tweepy.API(self.auth) # Change access details below to point to own application def download_data(self): # authenticating consumerKey = '' consumerSecret = '' accessToken = '' accessTokenSecret = '' auth = tweepy.OAuthHandler(consumerKey, consumerSecret) auth.set_access_token(accessToken, accessTokenSecret) # api = tweepy.API(auth) api = tweepy.API(auth, wait_on_rate_limit=True) # input for term to be searched and how many tweets to search searchTerm = input("Enter Keyword/Tag to search about: ") NoOfTerms = int(input("Enter how many tweets to search: ")) # searching for tweets self.tweets = tweepy.Cursor(api.search, q=searchTerm, lang="en").items(NoOfTerms) # Open/create a file to append data to csvFile = open('result.csv', 'a') # Use csv writer csvWriter = csv.writer(csvFile) # creating variables to store info polarity = 0 positive = 0 wpositive = 0 spositive = 0 negative = 0 wnegative = 0 snegative = 0 neutral = 0 # iterating through tweets fetched for tweet in self.tweets: # Append to temp so that we can store in csv later. I use encode UTF-8 self.tweetText.append(self.clean_tweet(tweet.text).encode('utf-8')) # print (tweet.text.translate(non_bmp_map)) #print tweet's text analysis = TextBlob(tweet.text) # print(analysis.sentiment) # print tweet's polarity polarity += analysis.sentiment.polarity # adding up polarities to find the average later if analysis.sentiment.polarity == 0: # adding reaction of how people are reacting to find average later neutral += 1 elif 0 < analysis.sentiment.polarity <= 0.3: wpositive += 1 elif 0.3 < analysis.sentiment.polarity <= 0.6: positive += 1 elif 0.6 < analysis.sentiment.polarity <= 1: spositive += 1 elif -0.3 < analysis.sentiment.polarity <= 0: wnegative += 1 elif -0.6 < analysis.sentiment.polarity <= -0.3: negative += 1 elif -1 < analysis.sentiment.polarity <= -0.6: snegative += 1 # Write to csv and close csv file csvWriter.writerow(self.tweetText) csvFile.close() # delete this for the insert SQL code bit # Attempt at SQLite code, couldn't get it right # con = lite.connect(r"C:\\Users\\Student User\\PycharmProjects\\DataScienceLabs\\tweets.db") # cur = con.cursor() # cur.execute('''CREATE TABLE tweets(created_at text, id_str text, text text)''') # commented out as models.py creates database # cur.execute("INSERT INTO tweets(?, ?, ?)", (created_at, # id_str, # text)) # con.commit() # finding average of how people are reacting positive = self.percentage(positive, NoOfTerms) wpositive = self.percentage(wpositive, NoOfTerms) spositive = self.percentage(spositive, NoOfTerms) negative = self.percentage(negative, NoOfTerms) wnegative = self.percentage(wnegative, NoOfTerms) snegative = self.percentage(snegative, NoOfTerms) neutral = self.percentage(neutral, NoOfTerms) # finding average reaction polarity = polarity / NoOfTerms # printing out data print("How people are reacting on " + searchTerm + " by analyzing " + str(NoOfTerms) + " tweets.") print() print("General Report: ") if polarity == 0: print("Neutral") elif 0 < polarity <= 0.3: print("Weakly Positive") elif 0.3 < polarity <= 0.6: print("Positive") elif 0.6 < polarity <= 1: print("Strongly Positive") elif -0.3 < polarity <= 0: print("Weakly Negative") elif -0.6 < polarity <= -0.3: print("Negative") elif -1 < polarity <= -0.6: print("Strongly Negative") print() print("Detailed Report: ") print(str(positive) + "% people thought it was positive") print(str(wpositive) + "% people thought it was weakly positive") print(str(spositive) + "% people thought it was strongly positive") print(str(negative) + "% people thought it was negative") print(str(wnegative) + "% people thought it was weakly negative") print(str(snegative) + "% people thought it was strongly negative") print(str(neutral) + "% people thought it was neutral") # self.plotPieChart(positive, wpositive, spositive, negative, wnegative, snegative, neutral, searchTerm, # NoOfTerms) 

    self.plotHist(positive, wpositive, spositive, negative, wnegative, snegative, neutral)

     def clean_tweet(self, tweet): # Remove links, special characters, etc., from tweet return ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t]) | (\w +:\ / \ / \S +)", " ", tweet).split()) # function to calculate percentage def percentage(self, part, whole): temp = 100 * float(part) / float(whole) return format(temp, '.2f') # def plotPieChart(self, positive, wpositive, spositive, negative, wnegative, snegative, neutral, searchTerm, noOfSearchTerms): # labels = ['Positive [' + str(positive) + '%]', 'Weakly Positive [' + str(wpositive) + '%]','Strongly Positive [' + str(spositive) + '%]', 'Neutral [' + str(neutral) + '%]', # 'Negative [' + str(negative) + '%]', 'Weakly Negative [' + str(wnegative) + '%]', 'Strongly Negative [' + str(snegative) + '%]'] # sizes = [positive, wpositive, spositive, neutral, negative, wnegative, snegative] # colors = ['yellowgreen', 'lightgreen', 'darkgreen', 'gold', 'red', 'lightsalmon', 'darkred'] # patches, texts = plt.pie(sizes, colors=colors, startangle=90) # plt.legend(patches, labels, loc="best") # plt.title('How people are reacting on ' + searchTerm + ' by analyzing ' + str(noOfSearchTerms) + ' Tweets.') # plt.axis('equal') # plt.tight_layout() # plt.show() 

    def plotHist(self, positive, wpositive, spositive, negative, wnegative, snegative, neutral):

    sentiments = [positive, wpositive, spositive, negative, wnegative, snegative, neutral]

    plt.xlabel('Sentiment Polarity')

    plt.ylabel('Sentiment Frequency')

    plt.hist(sentiments, bins=7, rwidth=0.95)

    plt.show()

    if __name__== "__main__": # db_init() sa = SentimentAnalysis() sa.download_data() 
    submitted by /u/Successful-Standard
    [link] [comments]

    What's a skill (like user interface designing) that one could learn in 20 hours using free online resources?

    Posted: 07 Apr 2020 08:38 AM PDT

    Scraping URLS Program Hangs after multiple 404 exceptions

    Posted: 07 Apr 2020 07:38 AM PDT

    So what I am trying to do is loop through an excel sheet with URLs, check each URL page content for "2017" and if it is there save an html copy to a certain folder, if there is no mention of 2017 it saves it to a different folder. Everything seemed to be going fine, but suddenly the program is hanging indefinitely for no apparent reason. It's currently happening when I get multiple 404 errors in a row.

    Here's the code

    #Load the relevant python libraries import pandas as pd import urllib import requests from urllib.request import HTTPError from urllib.request import urlopen from bs4 import BeautifulSoup as bs import traceback import os #load the dataframe DF = pd.read_excel("path to URL") Save2017 = "path to folder" Saveno2017 = "path to folder" #cycle through rows, open URL, if link is valid scrape for 2017, #if present save to folder for 2017 as an html file #if not present save to other folder for no 2017 as html file for index,row in DF.iterrows(): URLtemp = row["Did"] URLdecode = urllib.parse.unquote(URLtemp) searchWords = ["2017"] try: with urlopen(URLdecode) as f: output = f.read().decode() if output: for word in searchWords: if word in output: print("2017 found in Article",index) page = urllib.request.urlopen(URLdecode,timeout=5) with open(os.path.join(Save2017,"Article_"+str(index)+".html"),"w") as outFile: outFile.write(page.read().decode('utf-8')) print("Article",index,"written to Save2017 folder") else: print("2017 NOT found in Article",index) page = urllib.request.urlopen(URLdecode,timeout=5) with open(os.path.join(Saveno2017,"Article_"+str(index)+".html"),"w") as outFile: outFile.write(page.read().decode('utf-8')) print("Article",index,"written to SaveNo2017 folder") else: print("URL output invalid") pass except (urllib.error.URLError, urllib.error.HTTPError) as err: try: if err.code == 404: print("404 Error") pass else: raise pass except: print("Different error:",err.reason) pass 
    submitted by /u/ninjadude93
    [link] [comments]

    No comments:

    Post a Comment