list of all eBay categories and eBay category ids

it’s strange that a company like eBay doesn’t make it easy for sellers to get the resources they need. have you tried getting a complete list of all eBay categories? maybe with the eBay category tree? – you will find that there’s not a convenient download location, albeit there should be!

the “trick” so I’ve learned is to get it yourself.

here is a very short python script that will get your categories:

#! /usr/bin/env python
import tools as t
import xmltodict as xml
import requests
url = 'http://open.api.ebay.com/Shopping?callname=GetCategoryInfo&appid={}&siteid={}&CategoryID={}&version=729&IncludeSelector=ChildCategories'
app_id = 'XXXX' #get your own eBay app id
site_id = '3' # 3 is UK
to_get = [-1] # start at the top
done = []
categories = {}
if __name__ == "__main__":
    while len(to_get) > 0:
        cid = to_get.pop()
        re = requests.get(url.format(app_id, site_id, cid))
        root = xml.parse(re.text)
        cats = root['GetCategoryInfoResponse']['CategoryArray']['Category']
        for cat in cats:
            if cat['CategoryID'] not in categories:
                print(cat.get('CategoryName', 0))
                c = {'category_id': cat.get('CategoryID', 0),
                    'category_level': cat.get('CategoryLevel', 0),
                    'category_name': cat.get('CategoryName', 0),
                    'category_parent_id': cat.get('CategoryParentID', 0),
                    'leaf_category': cat.get('LeafCategory', 0),
                    'category_name_path': cat.get('CategoryNamePath', 0)}
                categories[cat['CategoryID']] = c
            done.append(cid)
            if cat['CategoryID'] not in done  and cat['LeafCategory'] == 'false' :
                to_get.append(cat['CategoryID'])
    with open('eBay_categories.tsv', 'w', encoding="utf-8") as of:
        of.write("category_idtcategory_leveltcategory_nametcategory_parent_idtleaf_categorytCategoryNamePathn")
        for k,v in categories.items():
            of.write(str(v['category_id']) + "t" + str(v['category_level']) + "t" + str(v['category_name']) + "t" + str(v['category_parent_id']) + "t" + str(v['leaf_category']) + "t" + str(v['category_name_path']) + "n")
the above will then create a tab-delimited text file named ‘eBay_categories.tsv’.
please note you will need both the “requests” and the “xmltodict” modules. they can be easily obtained using pypi. this code is python 3

Auto Download File From FTP – then rename

A little while ago my friend asked me to help him with some Windows commandline scripting. Basically he was waiting for ages for the development team in his company to sort this simple task out and asked me how he can every day automatically download a file from FTP, then rename it with the current date.

I don’t do Windows very much and Linux is just much better for exactly these things, but this seemed like an easy enough challenge.

In the end I didn’t manage to do everything in one file, but I think that two should work just as well when you add them to the Windows task scheduler…

Here are the files with some explanation:

downloader.bat:

@ftp -i -s:”%~f0″&GOTO:EOF
open ftp.someserver.com
[username]
[password]
!:— FTP commands below here —
mget “*.*”
disconnect

The first line starts the windows command line FTP client and the parameters essentially say that everything else in the file should be ignored by the command line itself, but be parsed to the FTP client.
Line two opens the connection and line three and four will send the authentication details. Line six gets all files in the current directory. You could really do here anything you want on the remote and local server, eg: change the local directory path (lcd …), the remote one (cd …) send files (put) or even delete them (rm). At the end, I simply disconnect.
renamer.bat:

for /f “tokens=1-5 delims=/ ” %%d in (“%date%”) do rename “SomeFileName.txt” SomeFileName_%%f-%%e-%%d.txt

In one line: I’m starting a for-loop and I use a tokeniser to delimit the following string into 5 (1-5) sections. %%d specifies the beginning character used for the token (d) and all that follow will be e,f,g…
then I use the %date% (in (“%date%”) function to get the current date. Now, In the do part, I will rename the file from SomeFileName.txt to SomeFileName_yyyy-MM-dd.txt
I hope this makes sense and helps a few people. Best of luck…

Script to disable & enable touchpads

I constantly touch the touchpad when I type. I also normally use an external mouse when I’m on my laptop. I seldom really need it, but I will sometimes want to switch it on (or off).

First you need to find the name of your touchpad in the xinput list:

$ xinput list

⎡ Virtual core pointer                     id=2 [master pointer  (3)]

⎜   ↳ Virtual core XTEST pointer               id=4 [slave  pointer  (2)]

⎜   ↳ Razer Razer Imperator                   id=10 [slave  pointer  (2)]

⎜   ↳ Razer Razer Imperator                   id=11 [slave  pointer  (2)]

⎜   ↳ PS/2 Mouse                               id=13 [slave  pointer  (2)]

⎜   ↳ AlpsPS/2 ALPS GlidePoint                 id=14 [slave  pointer  (2)]

⎣ Virtual core keyboard                   id=3 [master keyboard (2)]

    ↳ Virtual core XTEST keyboard             id=5 [slave  keyboard (3)]

    ↳ Sony Vaio Keys                           id=6 [slave  keyboard (3)]

    ↳ Video Bus                               id=7 [slave  keyboard (3)]

    ↳ Power Button                             id=8 [slave  keyboard (3)]

    ↳ USB 2.0 Camera                           id=9 [slave  keyboard (3)]

    ↳ AT Translated Set 2 keyboard             id=12 [slave  keyboard (3)]

So in my case the touchpad is most likely: PS/2 Mouse on id 13.

You can easily identify if the device is “on” (enabled):

$ xinput list-props “PS/2 Mouse” 

Device ‘PS/2 Mouse’:

Device Enabled (144): 1

Coordinate Transformation Matrix (146): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000

Device Accel Profile (267): 0

Device Accel Constant Deceleration (268): 1.000000

Device Accel Adaptive Deceleration (269): 1.000000

Device Accel Velocity Scaling (270): 10.000000

Evdev Axis Inversion (271): 0, 0

Evdev Axes Swap (273): 0

Axis Labels (274): “Rel X” (154), “Rel Y” (155)

Button Labels (275): “Button Left” (147), “Button Middle” (148), “Button Right” (149), “Button Wheel Up” (150), “Button Wheel Down” (151)

Evdev Middle Button Emulation (276): 0

Evdev Middle Button Timeout (277): 50

Evdev Wheel Emulation (278): 0

Evdev Wheel Emulation Axes (279): 0, 0, 4, 5

Evdev Wheel Emulation Inertia (280): 10

Evdev Wheel Emulation Timeout (281): 200

Evdev Wheel Emulation Button (282): 4

Evdev Drag Lock Buttons (283): 0

 Now create yourself a little file (eg: “touchpad”):

# toggle synaptic touchpad on/off

SYNSTATE=$(xinput list-props “PS/2 Mouse” | grep Enabled | grep -Eo ‘.$’)

if [ $SYNSTATE = 0 ]; then xinput set-int-prop “PS/2 Mouse” “Device Enabled” 8 1

else xinput set-int-prop “PS/2 Mouse” “Device Enabled” 8 0; fi

dengar@dengar-vaio:/usr/bin$ $ xinput list-props “PS/2 Mouse” 

This should sort you out. Don’t forget to  change the name of your actual device, remember mine is “PS/2 Mouse”

Next you need to make the file executable:

sudo chmod +x touchpad

Now, to have that file available from the command line, simply copy it to /usr/bin.