User Tools

Site Tools


task_boiler

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
task_boiler [2023/05/03 16:42] admintask_boiler [2024/01/22 22:59] – [Issue] raju
Line 4: Line 4:
 Start the first heading with "=====" Start the first heading with "====="
  
-===== find depth ===== +===== blocked by barrons ===== 
-==== find depth of a file or directory ====+==== Issue ==== 
 +barrons.com is giving the following error.
 <code> <code>
-import os +You have been blocked.
-  +
-def get_depth(file_or_dir_path): +
-    abs_path = os.path.abspath(os.path.expanduser(file_or_dir_path)) +
-    depth = os.path.normpath(abs_path).count(os.sep) +
-    return depth +
-</code>+
  
-Examples: +Why? 
-<code> +Something about the behaviour of the browser has caught our 
-In [2]:  +attention.
-os.path.abspath(os.path.expanduser('~')) +
-Out[2]:  +
-'/home/rajulocal'+
  
-In [3]:  +There are various possible explanations for this
-[get_depth('~'), get_depth('/home/rajulocal'), get_depth('/home/rajulocal/'), +* You are browsing and clicking at a speed much faster than 
- get_depth('/home/rajulocal/foo'), get_depth('/'), get_depth('/home')] +  expected of a human being. 
-Out[3]:  +* Something is preventing JavaScript from working on your 
-[2, 2, 2, 3, 1, 1] +  computer. 
-</code>+* There is a robot on the same network (IP WW.XX.YY.ZZ) as you.
  
-Using Python 3.10.6, Ipython 8.6.0 +Having problems accessing the site? Submit feedback
- +ID: a-b-c-d-e
-tags | measure the depth of a file system path +
- +
-See also: +
-  * https://stackoverflow.com/questions/31528199/how-to-measure-the-depth-of-a-file-system-path shows how to do it with various command line tools. +
-  * https://docs.python.org/3/library/os.path.html +
- +
-==== depth of a directory relative to a parent directory ==== +
-<code> +
-import os +
-  +
-def dir_depth_relative(child, parent): +
-    child = os.path.abspath(os.path.expanduser(child)) +
-    parent = os.path.abspath(os.path.expanduser(parent)) +
-    assert child.startswith(parent), "child parent relation violated. parent = " + parent + ', child = ' + child +
-    name_space = os.path.relpath(child, parent) +
-    level = os.path.normpath(name_space).count(os.sep) + 1 if name_space != '.' else 0 +
-    return level+
 </code> </code>
  
-Examples: +==== Solution ==== 
-<code+Click on the extensions button in the top right 
-In [2]:  +-Bypass Paywalls Clean -> settings button -> Options 
-[dir_depth_relative('~', '~'), dir_depth_relative('~', '~/'), +-> scroll down to "BPC settings" section 
- dir_depth_relative('~/work', '~'), dir_depth_relative('~/work.txt', '~'), +-> check "Barron's - no Googlebot (http error 500)" option 
- dir_depth_relative('/tmp/foo', '/tmp'), dir_depth_relative('/tmp', '/tmp'), +-> Save
- dir_depth_relative('/tmp/foo/bar', '/tmp')] +
-Out[2]:  +
-[0, 0, 1, 1, 1, 0, 2]+
  
-In [3] +==== System Information ==== 
-dir_depth_relative('/tmp', '/tmp/foo'+  * bypass paywalls clean extension version: 3.5.2.(latest asof 2024-01-22
---------------------------------------------------------------------------- +  * google chrome: 120.0.6099.200 
-AssertionError                            Traceback (most recent call last) +  * OSWindows 10 Enterprise
-Cell In [3], line 1 +
-----> 1 dir_depth_relative('/tmp', '/tmp/foo'+
- +
-Cell In [1], line 6, in dir_depth_relative(child, parent) +
-      4 child = os.path.abspath(os.path.expanduser(child)) +
-      parent = os.path.abspath(os.path.expanduser(parent)) +
-----> 6 assert child.startswith(parent), "child parent relation violated. parent = " + parent + ', child = ' + child +
-      7 name_space = os.path.relpath(child, parent) +
-      8 level = os.path.normpath(name_space).count(os.sep) + 1 if name_space != '.' else 0 +
- +
-AssertionErrorchild parent relation violated. parent = /tmp/foo, child = /tmp +
-</code>+
  
task_boiler.txt · Last modified: 2024/01/23 22:55 by raju