Search This Blog

Showing posts with label debugging. Show all posts
Showing posts with label debugging. Show all posts

Wednesday, November 1, 2017

Python libraries bugs and coincidences with criminal numerology


Today I installed several libraries to crawl websites and to  repair bugs on no parse module. The projects installed were arsespyder-0.0.3.tar.gz, parse-1.8.2.tar.gz, urlparse2-1.0.tar.gz (copied installation files names).  So I get new error even after uninstallation which not allow me parse and scrap even on website urls. The funnest things is that new error lines concides with criminal numerology. So my solution for debugging to uninstall libraries and install again.

File "C:\Python27\lib\urllib2.py", line 94, in <module> 9+4 = 13 (death)
File "C:\Python27\lib\httplib.py", line 74, in <module> 7+4 = 11 (cunning)
File "C:\Users\ANTRAS\Desktop\urlparse.py", line 4, in <module> 4 (Dostojevski acopalypsis)
File "C:\Python27\lib\urllib.py", line 33, in <module>33 Christ age - Year of death of prophet.

Now I remember programmers book (Think like computer scientist) where debugging is described as detective job and even word 'bug' origins with 13 and F (6 - satan digir) crime numerolgy. 



So I debugged the problem. It was fault since on Desktop I had urlpasrse.py for testing and urlparse is considered keyword reserved by python. Some how I also on Desktop I found urlparse.py. So this coincidence raises hypothesis that error with line 33 can be deliberated code line to show double reserved keyword file. Simple 33 is resurection. Simple to debug.


#python LINKS.py
#cd C:\Users\ANTRAS\Desktop

import urllib2
import re

#connect to a URL
website = urllib2.urlopen('http://www......../')
html = website.read()
#use re.findall to get all the links
links = re.findall('"((http|ftp)s?://.*?)"', html)

#print links


C:\Users\ANTRAS\Desktop>python LINKS.py
Traceback (most recent call last):
  File "LINKS.py", line 4, in <module>
    import urllib2
  File "C:\Python27\lib\urllib2.py", line 94, in <module>
    import httplib
  File "C:\Python27\lib\httplib.py", line 74, in <module>
    from urlparse import urlsplit
  File "C:\Users\ANTRAS\Desktop\urlparse.py", line 4, in <module>
    from urllib.parse import urlparse
  File "C:\Python27\lib\urllib.py", line 33, in <module>
    from urlparse import urljoin as basejoin
ImportError: cannot import name urljoin

Below I share List of my python libraries, partly for advertising my experience. Most libraries are dependencies, some for productivity, some for trial to debug, some to test, some are fully used and parts of codes copied.

AccessControl (3.0.12) Jinja2 (2.9.6) pyzmq (16.0.2)
Acquisition (4.2.2) jmespath (0.9.0) qcsv (0.0.6)
adblockparser (0.7) jsonify (0.5) qtconsole (4.3.1)
affinegap (1.10) jsonschema (2.5.1) query-string (0.0.0)
alabaster (0.7.8) jupyter (1.0.0) queuelib (1.4.2)
alembic (0.8.6) jupyter-client (5.1.0) ranking (0.3.1)
amqp (1.4.9) jupyter-console (5.2.0) raven (5.21.0)
anyjson (0.3.3) jupyter-core (4.3.0) Record (3.1)
arrow (0.8.0) keystoneauth1 (2.8.0) recordtype (1.1)
ARS (0.5b1) kombu (3.0.35) redis (2.10.5)
asn1crypto (0.23.0) lazy-object-proxy (1.2.2) repoze.lru (0.6)
astroid (1.4.6) linecache2 (1.0.0) request (0.0.0)
attrs (16.1.0) linkGrabber (0.3.0) requests (2.18.4)
awscli (1.10.38) links-from-link-header (0.1.0) RestrictedPython (3.6.0)
Babel (2.3.4) loadcsv (0.4) retrying (1.3.3)
backports-abc (0.4) lockfile (0.12.2) rlr (2.4)
backports.csv (1.0.1) logilab-common (1.2.2) robotframework (3.0)
backports.shutil-get-terminal-size (1.0.0) losser (0.0.3) robotframework-selenium2library (1.7.4)
backports.ssl-match-hostname (3.5.0.1) lxml (4.1.0) robotframework-xlsxlibrary (0.1.0.1)
bcdoc (0.16.0) Mako (1.0.4) rq (0.7.1)
beautifulsoup4 (4.6.0) Markdown (2.6.6) rq-scheduler (0.7.0)
billiard (3.3.0.23) MarkupSafe (1.0) rsa (3.4.2)
Biryani (0.10.4) matplotlib (1.5.3) s3transfer (0.0.1)
bleach (2.1.1) mccabe (0.5.0) scandir (1.6)
blessings (1.6) mechanize (0.3.6) schedule (0.4.2)
blinker (1.4) meld3 (1.0.2) scikit-learn (0.17.1)
boto (2.40.0) MetaCSV (0.0.8) Scrapy (1.1.2)
botocore (1.4.28) Metafone (0.5) selenium (3.5.0)
breadability (0.1.20) micropython-csv (0.0.0) semver (2.7.9)
BTrees (4.3.1) Missing (3.1) SeoAnalyzer (0.0.1)
canonicalize (1.3) mistune (0.7.4) SerpScrap (0.9.1)
cassette (0.3.8) mock (2.0.0) service-identity (16.0.0)
categorical-distance (1.9) monotonic (1.1) setupfiles (0.0.50)
celery (3.1.23) mosaik-api (2.2) setuptools (36.6.0)
certifi (2017.7.27.1) mosaik-csv (1.0.2) setuptools-git (1.1)
cffi (1.11.2) mozcrash (0.17) simplecosine (1.1)
chardet (3.0.4) mozdevice (0.48) simplecsvtools (0.5)
clg (2.2.0) mozfile (1.2) simplegeneric (0.8.1)
click (6.6) mozinfo (0.9) simplejson (3.8.2)
clif (0.2.2) mozlog (3.2) simpy (3.0.9)
cmd2 (0.6.8) moznetwork (0.27) simpy.io (0.2.2)
collective.csv2dict (1.1) mozprocess (0.22) singledispatch (3.4.0.3)
collective.wtf (1.0b9) mozprofile (0.28) six (1.11.0)
colorama (0.3.9) mozrunner (6.11) smart-image-renamer (unknown)
combine2xlsx (0.1.9) mpmath (0.19) smartcsv (0.2.3)
comma (0.1) msgpack-python (0.4.7) snowballstemmer (1.2.1)
compago (-versiontools-compago-) MultiMapping (3.0) SOAPpy (0.12.22)
comtypes (1.1.3) mutils (1.0.5) South (1.0.2)
configobj (5.0.6) mysql-connector (2.1.4) Sphinx (1.4.4)
configparser (3.5.0) mysql2csv (0.2) SQLAlchemy (1.1.13)
contextlib2 (0.5.3) mysqlclient (1.3.7) sqlparse (0.1.19)
cordwainer (0.0.2) nbconvert (5.3.1) statsd (3.2.1)
cov-core (1.15.0) nbformat (4.4.0) stevedore (1.15.0)
coverage (4.1) ndg-httpsclient (0.4.1) subprocess.run (0.0.8)
coveralls (1.1) netaddr (0.7.18) suds (0.4)
croniter (0.3.16) netCDF4 (1.2.4) summary-extraction (0.2)
cryptography (2.1.2) netifaces (0.10.4) sumy (0.7.0)
cs.csvutils (20150116) newrelic (2.66.0.49) supervisor (3.3.0)
cs.nodedb (20150118) ninja (1.7.2.post2) sympy (1.0)
cssselect (1.0.1) nltk (3.2.5) table2csv (0.1.3)
CSV-anomaly-detector (1.2.17) nose (1.3.7) tablereader (1.0.3)
csv-object-reader (0.1.1) nose-parameterized (0.6.0) tablib (0.11.2)
csv-to-table (0.0.3) notebook (5.1.0) tabulate (0.7.5)
csv2odoo (0.7.5) nt-svcutils (2.13.0) tabview (1.4.2)
csv2xls (0.4) numpy (1.13.3) tcsv2png (1.0.1)
csv2xlsx (0.1.2) oauth2 (1.9.0.post1) tempstorage (3.0)
csvconvert (0.1) oauth2client (3.0.0) testpath (0.3.1)
csvcool (0.3.5) oauthlib (1.1.2) testtools (2.2.0)
csvdedupe (0.1.13) odswriter (0.4.0) thread (0.1.0)
csvdiff (0.3.1) olefile (0.44) threading2 (0.3.1)
csvfilter (0.3.1) openpyxl (2.3.5) thrift (0.9.3)
csvImporter (0.1.3.2) optparse-pretty (0.1.1) tornado (4.3)
csvkit (0.9.1) ordereddict (1.1) tox (2.3.1)
csvlib (1.0.2) oslo.config (3.11.0) traceback2 (1.4.0)
csvmatch (1.10) oslo.i18n (3.7.0) traitlets (4.2.1)
csvmerge (1.0.9) errors csv oslo.serialization (2.9.0) transaction (1.6.1)
csvpivot (1.1) oslo.utils (3.13.0) Twisted (16.4.0)
csvpp (0.2.0) pandas (0.20.3) txAMQP (0.6.2)
CSVSee (0.2) pandocfilters (1.4.2) ujson (1.35)
csvwriter (0.2.2) paramiko (1.17.0) unicodecsv (0.14.1)
csvx (0.1.1459403998) parsel (1.0.3) unittest2 (1.1.0)
csvxls (0.2) Paste (2.0.3) uritemplate (0.6)
cutplace (0.8.8) PasteDeploy (1.5.2) urllib3 (1.22)
cycler (0.10.0) path.py (8.2.1) vcr (0.0.9)
Cython (0.27.1) pathlib2 (2.3.0) vcrpy (1.11.1)
DancingPeasant (0.1.6) pbr (3.1.1) versiontools (1.9.1)
darcsver (1.7.4) pep8 (1.7.0) virtualenv (15.0.2)
DateTime (4.1.1) Persistence (2.13.2) vladiate (0.0.11)
DB2CSV (0.1b3) persistent (4.2.1) w3lib (1.18.0)
dbf (0.94.3) pexpect (4.1.0) waitress (0.9.0)
debtcollector (1.5.0) pickleshare (0.7.2) Wave (0.0.2)
decorator (4.0.10) pika (0.10.0) wcwidth (0.1.7)
dedupe (1.3.1) Pillow (4.3.0) webencodings (0.5.1)
dedupe-hcluster (0.3.2) pip (9.0.1) WebOb (1.7.3)
defusedxml (0.4.1) plone.memoize (1.2.0) websocket (0.2.1)
distribute (0.7.3) pluggy (0.3.1) websocket-client (0.37.0)
Distutils2 (1.0a4) popen (0.1.20) WebTest (2.0.21)
Django (1.9.7) positional (1.1.0) Werkzeug (0.11.10)
django-adaptors (0.2.5) post (0.0.0) wheel (0.29.0)
django-debug-toolbar (1.4) pprint (0.1) widgetsnbextension (3.0.3)
django-extensions (1.6.7) prettytable (0.7.2) wincertstore (0.2)
django-queryset-csv (0.3.3) Products.BTreeFolder2 (2.14.0) wrapcsv (0.0.1)
djangorestframework (3.3.3) Products.CMFCore (2.3.0) wrapt (1.10.8)
djangorestframework-csv (1.4.1) Products.DCWorkflow (2.2.4) wstools (0.4.3)
docker-py (1.8.1) Products.ExternalMethod (2.13.1) xarray (0.7.2)
docopt (0.6.2) Products.GenericSetup (1.8.3) xlrd (0.9.3)
DocumentTemplate (2.13.2) Products.MailHost (2.13.2) xlsx2csv (0.7.2)
docutils (0.12) Products.MIMETools (2.13.0) Xlsxcursor (0.1.7)
DoubleMetaphone (0.1) Products.OFSP (2.13.2) xlsxdiff (0.2)
dropcols (1.0.1.0) Products.PythonScripts (2.13.2) XlsxWriter (0.9.2)
easycsv (0.8.0) Products.StandardCacheManagers (2.13.1) xlwt (1.3.0)
easyxlsx (0.2.9) Products.ZCatalog (3.1) yamlordereddictloader (0.1.1)
ecdsa (0.13) Products.ZCTextIndex (2.13.5) yamlreader (3.0.4)
elasticsearch (2.3.0) Products.ZSQLMethods (2.13.4) yolk (0.4.3)
entrypoints (0.2.3) prompt-toolkit (1.0.15) zc.buildout (2.5.2)
enum34 (1.1.6) psutil (5.2.2) zc.lockfile (1.2.1)
et-xmlfile (1.0.1) psycopg2 (2.6.1) ZConfig (3.1.0)
eventlet (0.19.0) ptyprocess (0.5.1) zdaemon (4.1.0)
excellent (0.0.5) public (0.0.0) ZEO (4.2.0)
ExtensionClass (4.1.2) py (1.4.34) zExceptions (3.0)
extraction (0.2) py-xlsx (0.4.1) zLOG (3.0)
extras (1.0.0) pyaml (17.10.0) ZODB (5.0.0a1)
Fabric (1.11.1) pyasn1 (0.1.9) ZODB3 (3.11.0)
fastcluster (1.1.20) pyasn1-modules (0.0.8) zodbpickle (0.6.0)
ffmpeg-normalize (0.2.4) pycodestyle (2.0.0) zope.annotation (4.4.1)
five.globalrequest (1.0) pycparser (2.18) zope.browser (2.1.0)
five.localsitemanager (2.0.5) pycrypto (2.6.1) zope.browsermenu (4.1.1)
fixed2csv (0.2.4) pycurl (7.43.0) zope.browserpage (4.1.0)
fixtures (3.0.0) PyDispatcher (2.0.5) zope.browserresource (4.1.0)
flake8 (2.6.0) pydub (0.16.6) zope.component (4.2.2)
Flask (0.11.1) pyexcel-io (0.2.0) zope.configuration (4.0.3)
funcsigs (1.0.2) pyexcel-xlsx (0.2.0) zope.container (4.1.0)
functools32 (3.2.3.post2) pyExcelerator (0.6.4.1) zope.contentprovider (4.0.0)
future (0.15.2) pyflakes (1.2.3) zope.contenttype (4.1.0)
futures (3.0.5) Pygments (2.1.3) zope.datetime (4.1.0)
gdata (2.0.18) pyhacrf-datamade (0.2.0) zope.deferredimport (4.1.0)
get (0.0.0) PyLBFGS (0.2.0.3) zope.dottedname (4.1.0)
gevent (1.2.2) pylint (1.5.6) zope.event (4.2.0)
gi (1.2) pymongo (3.2.2) zope.exceptions (4.0.8)
git-url-parse (1.0.0) pyOpenSSL (17.3.0) zope.filerepresentation (4.1.0)
glob2 (0.4.1) pypiwin32 (219) zope.formlib (4.3.0)
GLSapp (0.2) pyramid-tablib (0.2) zope.globalrequest (1.2)
google-api-python-client (1.5.3) PySocks (1.6.7) zope.i18n (4.1.0)
greenlet (0.4.12) pystache (0.5.4) zope.i18nmessageid (4.0.3)
GRobot (0.0.13) pytest (3.2.3) zope.index (4.2.0)
gunicorn (19.6.0) pytest-cov (2.2.1) zope.interface (4.3.1)
haversine (0.4.5) pytest-vcr (0.3.0) zope.lifecycleevent (4.1.0)
highered (0.2.0) python-csv (0.0.10) zope.location (4.0.3)
html2text (2017.10.4) python-daemon (2.1.1) zope.pagetemplate (4.2.1)
html5lib (1.0b10) python-dateutil (2.6.1) zope.processlifetime (2.1.0)
http-parser (0.8.3) python-editor (1.0.1) zope.proxy (4.2.0)
httplib2 (0.10.3) python-gflags (3.0.5) zope.ptresource (4.0.0)
hyperlink (17.3.1) python-keystoneclient (3.1.0) zope.publisher (4.2.2)
idna (2.6) python-memcached (1.58) zope.ramcache (2.1.0)
image (1.5.4) python-mimeparse (1.5.2) zope.schema (4.4.2)
imagebot (1.2.1) python-novaclient (4.1.0) zope.security (4.0.3)
imagesize (0.7.1) python-subprocess2 (2.0.2) zope.sendmail (4.0.1)
imutils (0.3.6) python-subunit (1.2.0) zope.sequencesort (4.0.1)
initgroups (2.13.0) python-swiftclient (3.0.0) zope.site (4.0.0)
ipaddress (1.0.18) pytrends (4.3.0) zope.size (4.1.0)
ipykernel (4.6.1) pytz (2017.2) zope.structuredtext (4.1.0)
ipython (4.2.0) pyutilib.common (3.0.7) zope.tal (4.2.0)
ipython-genutils (0.1.0) pyutilib.component.config (3.8) zope.tales (4.1.1)
ipywidgets (7.0.1) pyutilib.component.core (4.6.4) zope.testbrowser (4.0.4)
iso8601 (0.1.11) pyutilib.component.executables (3.5) zope.testing (4.5.0)
isodate (0.5.4) pyutilib.misc (5.9.1) zope.traversing (4.0.0)
itsdangerous (0.24) pyutilib.services (3.4) zope.viewlet (4.0.0)
jdcal (1.2) pyutilib.subprocess (3.6.2) Zope2 (2.13.24)
jellyfish (0.5.1) pywinauto (0.6.3) ZopeUndo (4.1)
Jinja2 (2.9.6) PyYAML (3.12)

Sunday, October 1, 2017

REWRITING, DEBUGGING, TESTING

I have to remind myself the job have done to complete integration of automated program and to test for reliability. The way you organize programming is also important.
Firstly, audit and remind what has been done. In this case I have code of twelve operations;
Secondly, today I found that converting code to colorful html file is practical to visually discern operations and read code. It is great! It will simplify tasks and save time. Similar way I read it in pywinauto shell;
Thirdly, keep in mind to debug errors finding error on command prompt screen and splitting code; Fourthly, to save time I program Autohotkey commands to write repetitive words and paths and open necessary window. It makes you efficient;
Fifth; I will amend this twelve operations codes to simplify working only with downloaded text files, Writing code you add on right code to another. You can watch video of how perform 12 functions.







#python 12345678910OPERACIJA.py
#cd C:\Users\Vartotojas\Desktop\OK1\

import csv
import os
import time
import re
import codecs
import sys
import shutil
import pandas

#PAKEISTI APJUNGTI TEKSTINIUS FAILUS, ISVALYTI BESIDUBLIUOJANCIUS,PASALINTU SU NEREIKALINGAI ZODZIAI

filename1 = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\LINKINPUT.csv'
filename2 = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\LINKINPUT.txt'
filename3 ='C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPSOUTPUT.txt'
filename4 = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPSOUTPUT1.txt'

with open(filename1, 'rb') as inf:
    reader = csv.reader(inf)
    with open(filename2, 'wb') as out:
        writer = csv.writer(out, delimiter='\t')
        writer.writerows(reader)

time.sleep(3)

filename21 = 'LINKINPUT1.txt'


def addUTF8Bom(filename):
  f = codecs.open(filename2, 'r', 'utf-8')
  content = f.read()
  f.close()
  f2 = codecs.open(filename21, 'w', 'utf-8')
  f2.write(u'\ufeff')
  f2.write(content)
  f2.close()

addUTF8Bom(filename2)

shutil.copy(filename21, filename2)
os.remove(filename21)

time.sleep(3)

name = "facebook.com/groups/"

newfile = open(filename3, 'w')
for line in file(filename2, 'r'):
    if name in line:
        newfile.write(line)
newfile.close()

time.sleep(3)

bad_words = ['permalinks']

with open(filename3, 'r') as oldfile, open(filename4, 'w') as newfile:
    for line in oldfile:
        if not any(bad_word in line for bad_word in bad_words):
            newfile.write(line)

time.sleep(3)

#somefile = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPSOUTPUT1.txt'
filename5 = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPGROUPLINK.txt'

with open(filename4, 'r') as infile, open(filename5, 'w') as newfile:
    for line in infile:
        newfile.write(line.split()[0] + '\n')

time.sleep(3)

#somefile = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPSOUTPUT1.txt'
filename6 = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPGROUPNAME.txt'


f = open(filename4, "r")
g = open(filename6, "w")
for line in f:
    if line.strip():
        g.write("\t".join(line.split()[1:]) + "\n")
f.close()
g.close()

time.sleep(3)

filename7 = 'C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPGROUPNAME1.txt'

prefix = ""
suffix = "QQQQQQ"

with open(filename6, 'r') as src:
    with open(filename7, 'w') as dest:
       for line in src:
           dest.write('%s%s%s\n' % (prefix, line.rstrip('\n'), suffix))

time.sleep(3)

filename8 = "C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPGROUPNAME2.txt"

fin = open(filename7, 'r')#PIRMA SUNEMARUS
output = open(filename8, 'w')
text1 = fin.read()
change =  re.sub(r'[^\w]','', text1) #re.sub(r'[^\w\s]','', text1) #REIKALINGA  PIRMAM KARTUI
print change
output.write(change)
fin.close()
output.close()

time.sleep(3)

filename9 = "C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPGROUPNAME3.txt"

fin = open(filename8, 'r')#PIRMA SUNEMARUS
output = open(filename9, 'w')
text1 = fin.read()
change =  re.sub(r'QQQQQQ','\n', text1) #re.sub(r'[^\w\s]','', text1) #REIKALINGA  PIRMAM KARTUI
print change
output.write(change)
fin.close()
output.close()

time.sleep(3)

filename10 = "C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPGROUPLINK1.txt"

fin = open(filename5, 'r')#PIRMA SUNEMARUS
output = open(filename10, 'w')
text1 = fin.read()
change =  re.sub(r'https://www.facebook.com/groups/','', text1) #re.sub(r'[^\w\s]','', text1) #REIKALINGA  PIRMAM KARTUI
print change
output.write(change)
fin.close()
output.close()

time.sleep(3)

filename11 = "C:\\Users\\Vartotojas\\Desktop\\OK1\\FBGROUPGROUPLINK2.txt"

fin = open(filename10, 'r')#PIRMA SUNEMARUS
output = open(filename11, 'w')
text1 = fin.read()
change =  re.sub(r'/','', text1) #re.sub(r'[^\w\s]','', text1) #REIKALINGA  PIRMAM KARTUI
print change
output.write(change)
fin.close()
output.close()

time.sleep(3)

import itertools

filename12 = 'FBIDNAME.txt'

from itertools import izip
with open(filename12, 'w') as res, open(filename11) as f1, open(filename9) as f2:
    for line1, line2 in zip(f1, f2):
        res.write("{} {}\n".format(line1.rstrip(), line2.rstrip()))

time.sleep(3)   

os.remove(filename2)
os.remove(filename3)
os.remove(filename4)
os.remove(filename5)
os.remove(filename6)
os.remove(filename7)
os.remove(filename8)
os.remove(filename9)
os.remove(filename10)
os.remove(filename11)