1

Using Python 3.6.4 on MacBook Pro. Is there a smoother way in adding text file to be appended into the URL address bar?

Excuse my ignorance, I'm a novice to Python. And this was my best shot...

import urllib
import urllib.request
import urllib.parse

text = "Global ambitions with regional insight is a common mantra among local firms but not many have the financial backing and pedigree of this leading financial institution. While many brokerages have shut their doors or downsized, this trading firm has continued to grow and there are no plans to slow down now. Already with a portfolio of substantial institutional and private clients, it is important to offer a diverse range of products to meet demand.
Skills."

site_url = "http://www.wdylike.appspot.com/?"

file_contents_in_url = urllib.parse.urlencode({'q' : text})

check = site_url + file_contents_in_url
#print(check)

url = urllib.request.urlopen(check)
url_bytes = url.read()
#print(url_bytes)

site_url_contents = url_bytes.decode("utf8")
#print(site_url_contents)
zamir
  • 2,144
  • 1
  • 11
  • 23
  • 1
    "Smoother" how? It looks like you have a working solution. (I actually suspect that something like IFTTT might be what you really want, but it's hard to tell.) – Daniel Pryden Feb 22 '18 at 22:36
  • The label "text file" makes me think at "undefined size" this might hit some "max request size" limit, maybe you should try using POST instead of GET, but beside that ... what exactly is it that is not working ? What errors/problems have you encountered ? – Lohmar ASHAR Feb 22 '18 at 23:11
  • @DanielPryden it's not IFTTT, it's simpler than that. It's a Udacity task to use "wdylike.appspot.com" website to check for profanity words in our text file. They use Python 2. And it was quite easier to concatenate texts to the URL address bar. – Mustafa Attiya Feb 23 '18 at 09:12
  • @LohmarASHAR the code is working. But my question if there is simpler or more directed way of doing so. I imported three libraries to implement one task, is it OK? – Mustafa Attiya Feb 23 '18 at 09:18

0 Answers0