Python Forum
Can anyone help me successfully run this code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can anyone help me successfully run this code?
#11
(Aug-17-2023, 03:20 PM)deanhystad Wrote: Do you really mean "C:\Users\User\Desktop" or do you mean the desktop for the current user? If the latter, you can ask windows for the current user's %HOMEPATH%. This program lists all the files on your desktop.
import os
from pathlib import Path

desktop = Path(os.environ["USERPROFILE"]) / "Desktop"
print(*desktop.iterdir(), sep="\n")
To get paths for Desktop\tabs.json and Desktop\tabs_oldercopywithalternatelinks.json:
work_files = desktop / "the-great-suspender-restore-urls-0.4"
tabs_path = work_files / "tabs.json"
tabs_copy_path = work_files / "bs_oldercopywithalternatelinks.json" 
if the path is really hard coded (will always be C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4), use a string. I suggest changing the "\" to "/" so Python doesn't interpret "\the" as "<tab>he".
from pathlib import Path

work_files = Path("C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4")
tabs_path = work_files / "tabs.json"
tabs_copy_path = work_files / "bs_oldercopywithalternatelinks.json"

I chose the third code excerpt, as it's exactly what I need! ^_^ Just one more question: Where exactly do I put the third code excerpt into the main code?
Reply
#12
snippsat Wrote:
# Now give path to file rand.json
(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --in-file=C:/Users/Tom/Desktop/rand.json --out-file=C:/Users/Tom/Desktop/jsontabs-restored.json
As i shown before in you give Path to files.
restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_new.json
I would have navigate in command line(cd) to C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4.
Then you just need to use file names.
restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs_new.json
Reply
#13
(Sep-08-2023, 02:15 PM)snippsat Wrote:
snippsat Wrote:
# Now give path to file rand.json
(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --in-file=C:/Users/Tom/Desktop/rand.json --out-file=C:/Users/Tom/Desktop/jsontabs-restored.json
As i shown before in you give Path to files.
restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_new.json
I would have navigate in command line(cd) to C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4.
Then you just need to use file names.
restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs_new.json

OK, I'm gonna try the whole thing again. :-) Hopefully, it'll FINALLY work...but if anything still goes wrong, I'll be sure to let you know. :-)

~~~

P.S.: Forgot to ask earlier: Do I need to type the command like this:

(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_restored.json

(suspender_env) G:\div_code\suspender_env
restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs_oldercopywithalternatelinks.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_oldercopywithalternatelinks_restored.json


Or this?

(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_restored.json
restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs_oldercopywithalternatelinks.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_oldercopywithalternatelinks_restored.json


I do hope I haven't been frustrating you with all these questions. ^^;;
Reply
#14
Like this.
restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs.json --out-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs_restored.json
You should learn to navigate on command line,here i demo in cmd i normal use cmder as it's much better.
Now i just put tabs.json on Desktop as a example,as you see when in that folder no path is needed.
If you don't use virtual environment,just forget about (suspender_env).
(suspender_env) G:\div_code\suspender_env>c:
C:\Users\Tom>cd ..
(suspender_env) C:\Users>cd ..
(suspender_env) C:\>cd Users
(suspender_env) C:\Users>cd Tom
(suspender_env) C:\Users\Tom>cd Desktop
# now in folder where tabs.json is
(suspender_env) C:\Users\Tom\Desktop>restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs_new.json
# No errors 
Reply
#15
(Sep-08-2023, 07:53 PM)snippsat Wrote: Like this.
restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs.json --out-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs_restored.json
You should learn to navigate on command line,here i demo in cmd i normal use cmder as it's much better.
Now i just put tabs.json on Desktop as a example,as you see when in that folder no path is needed.
If you don't use virtual environment,just forget about (suspender_env).
(suspender_env) G:\div_code\suspender_env>c:
C:\Users\Tom>cd ..
(suspender_env) C:\Users>cd ..
(suspender_env) C:\>cd Users
(suspender_env) C:\Users>cd Tom
(suspender_env) C:\Users\Tom>cd Desktop
# now in folder where tabs.json is
(suspender_env) C:\Users\Tom\Desktop>restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs_new.json
# No errors 

While I appreciate your effort, I'm afraid that wasn't really the question I asked. ^^;; I should probably rephrase it: Should I post (suspender_env) G:\div_code\suspender_env for each tabs JSON file individually, like this?

(suspender_env) G:\div_code\suspender_env
(File A)

(suspender_env) G:\div_code\suspender_env
(File B)


Or should I type (suspender_env) G:\div_code\suspender_env & post the code for both files one right after the other?

(suspender_env) G:\div_code\suspender_env
(File A)
(File B)
Reply
#16
(Sep-09-2023, 02:30 AM)TheMouseAvenger Wrote: While I appreciate your effort, I'm afraid that wasn't really the question I asked. ^^;; I should probably rephrase it: Should I post (suspender_env) G:\div_code\suspender_env for each tabs JSON file individually, like this?
You are really is confused here (suspender_env) G:\div_code\suspender_env is just my virtual environment.
I do test stuff out isolated,do you understand this?

If i install normal like you probably do from cmd.
# Install
C:\code>pip install the-great-suspender-restore-urls
Collecting the-great-suspender-restore-urls
  Using cached the_great_suspender_restore_urls-0.4-py3-none-any.whl (5.8 kB)
Installing collected packages: the-great-suspender-restore-urls
Successfully installed the-great-suspender-restore-urls-0.4

# It works just the same way 
C:\code>restore-the-great-suspender-urls --help
usage: restore-the-great-suspender-urls [-h] --in-file IN_FILE --out-file  OUT_FILE
..... 

# If i have tabs.json in this folder,it works
C:\code>restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs_new.json
Reply
#17
(Sep-09-2023, 02:35 PM)snippsat Wrote:
(Sep-09-2023, 02:30 AM)TheMouseAvenger Wrote: While I appreciate your effort, I'm afraid that wasn't really the question I asked. ^^;; I should probably rephrase it: Should I post (suspender_env) G:\div_code\suspender_env for each tabs JSON file individually, like this?
You are really is confused here (suspender_env) G:\div_code\suspender_env is just my virtual environment.
I do test stuff out isolated,do you understand this?

If i install normal like you probably do from cmd.
# Install
C:\code>pip install the-great-suspender-restore-urls
Collecting the-great-suspender-restore-urls
  Using cached the_great_suspender_restore_urls-0.4-py3-none-any.whl (5.8 kB)
Installing collected packages: the-great-suspender-restore-urls
Successfully installed the-great-suspender-restore-urls-0.4

# It works just the same way 
C:\code>restore-the-great-suspender-urls --help
usage: restore-the-great-suspender-urls [-h] --in-file IN_FILE --out-file  OUT_FILE
..... 

# If i have tabs.json in this folder,it works
C:\code>restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs_new.json

I'd much rather stick with Python, if you please. :-) And this is the address of my folder with my two JSON tabs files, which I have made the path for my computer's virtual environment: C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4 . In that case, what exactly should I type instead of your (suspender_env) G:\div_code\suspender_env?
Reply
#18
(Sep-09-2023, 04:01 PM)TheMouseAvenger Wrote: I'd much rather stick with Python, if you please. :-)
It's all Python that posted here just that you confused about it,my last post just install and use it without a virtual environment.

If you make a virtual environment as i do in post 6 ,you call it the same as me suspender_env or whatever you want.
when activate a environment it will have (suspender_env) first this is just to show that it activated.
Then can use restore-the-great-suspender-urls from any folder,
If you use virtual environment it will look like this (your environment name)C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4

If all this is confusing just to as do in post #16 without a virtual environment.
Try to step back and understand this,the virtual environment was not needed at all here all,
just that test a lot here on Forum and like to it isolated to make sure stuff work for Users.
Reply
#19
(Sep-09-2023, 04:50 PM)snippsat Wrote:
(Sep-09-2023, 04:01 PM)TheMouseAvenger Wrote: I'd much rather stick with Python, if you please. :-)
It's all Python that posted here just that you confused about it,my last post just install and use it without a virtual environment.

If you make a virtual environment as i do in post 6 ,you call it the same as me suspender_env or whatever you want.
when activate a environment it will have (suspender_env) first this is just to show that it activated.
Then can use restore-the-great-suspender-urls from any folder,
If you use virtual environment it will look like this (your environment name)C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4

If all this is confusing just to as do in post #16 without a virtual environment.
Try to step back and understand this,the virtual environment was not needed at all here all,
just that test a lot here on Forum and like to it isolated to make sure stuff work for Users.

*inhales deeply* All right, I think I may have finally gotten this code right!

G:\div_code
λ python -V
Python 3.11.3
 
G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)
 
# Make enviroment
G:\div_code
λ python -m venv suspender_env
 
G:\div_code
λ cd suspender_env\
 
G:\div_code\suspender_env
λ G:\div_code\suspender_env\Scripts\activate.bat

(suspender_env) G:\div_code\suspender_env
λ pip install the-great-suspender-restore-urls

(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_restored.json
(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --in-file=C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4/tabs_oldercopywithalternatelinks.json --out-file=C:/Users/User\Desktop/the-great-suspender-restore-urls-0.4/tabs_oldercopywithalternatelinks_restored.json

usage: restore-the-great-suspender-urls [-h] --in-file IN_FILE --out-file OUT_FILE [--session-name-suffix SESSION_NAME_SUFFIX]
                                        [--extension-id EXTENSION_ID] [--verbose]
 
Restore the broken URLs of the Great Suspender browser extension
 
options:
  -h, --help            show this help message and exit
  --in-file IN_FILE     Input file. Could be relative (to current directory)
  --out-file OUT_FILE   Output file. Could be relative (to current directory)
  --session-name-suffix SESSION_NAME_SUFFIX
                        Session name suffix. Defaults to ` - cleaned`.
  --extension-id EXTENSION_ID
                        ID of ``The Great Suspender`` extension. If left blank, regularexpression match will be used.
  --verbose             Verbose output.
Of course, if there are any errors, PLEASE do let me know. :-) It would also be very much appreciated if you could put any corrections IN the code, so I don't have to worry about placing them.
Reply
#20
(Sep-10-2023, 02:03 PM)TheMouseAvenger Wrote: Of course, if there are any errors, PLEASE do let me know. :-) It would also be very much appreciated if you could put any corrections IN the code, so I don't have to worry about placing them.
All is ok.
Now can give path or simpler just put .json files in folder G:\div_code\suspender_env then no path is needed.
Navigate works like with c: and cd if want go eg desktop.
G:\div_code\suspender_env                                                         
λ G:\div_code\suspender_env\Scripts\activate.bat                                  
 
# Over to c:                                                                                 
(suspender_env) G:\div_code\suspender_env                                         
λ c:                                                                              
           
# Go back                                                                       
(suspender_env) C:\Users\Tom                                                      
λ cd ..                                                                           
    
# Go back                                                                                 
(suspender_env) C:\Users                                                          
λ cd ..                                                                           
     
# Go to Desktop                                                                             
(suspender_env) C:\                                                               
λ cd Users/Tom/Desktop    

# List files 
(suspender_env) C:\Users\Tom\Desktop
λ ls
'010 Editor.lnk'*
 'tabs.json'
'tabs_new.json'
.....                                                      
       
# Do the command                                                                           
(suspender_env) C:\Users\Tom\Desktop                                              
λ restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs_new.json   
# No error ok
So now i this navigate demo i have a tabs.json in Destop folder,
then no Path is needed,same for all just navigate to folder where .json files are,or just move the files to suspender_env folder.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how do I successfully use PDO with my ODBC for MSSQL? cyberion1985 3 6,608 Jun-26-2018, 04:44 PM
Last Post: Maverick494
  Cannot successfully install NumPy aniketmone2017 3 7,385 Dec-29-2016, 02:14 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020