Summary

Every day, this script logs into our FreshDesk help centre, downloads every single help article as a html file + images (only new updates since last sync), lists any errors, and saves them as files on global share drive - so we always have a backup, even if FreshDesk disappears tomorrow and acts as an information resource for the SO AI Slack channel (Internal Site only).

The html file can be copied into a code view on FreshDesk to rebuild the article. 

Global Share Location - https://opus2.sharepoint.com/teams/Share/Shared%20Documents/Forms/AllItems.aspx?id=%2Fteams%2FShare%2FShared%20Documents%2FSolution%20Services%2FSolution%20Ops%2FFreshDesk%20Knowledge%20Base&viewid=45b178aa%2D836b%2D4587%2D9e0b%2Ddd02683268a8

What is FreshDesk?

FreshDesk is a website we use to write and publish help guides for our users. Think of it like a big online filing cabinet full of instructions. We have three separate sections (called "portals") inside it:

Portal nameWhat it's forID number
EBundleHelp guides for the EBundle product43000117160
HearingsHelp guides for the Hearings product43000117436
InternalInternal staff guides43000117454

Each portal contains categories (like chapters in a book), which contain folders (like sections in a chapter), which contain articles (the actual guides).


How are the files saved?

The script copies the same structure from FreshDesk onto Global Share, like this:

FreshDesk Back Ups/
  EBundle/
    Category Name/
      Folder Name/
        Bulk Organise.html
        Bulk Organise - Images/
          01_screenshot.png
          02_diagram.jpg
          03_example.png
  Hearings/
  Internal/
  last_sync.txt
  sync_log.txt

Each article is saved as a .html file you can open in any web browser by double-clicking it. Images are saved in their own folder next to the article, numbered in the order they appear.

  1. Images - downloaded and saved to the drive permanently. Even if FreshDesk disappears, you still have them.
  2. Videos - cannot be downloaded (YouTube, Vimeo etc. don't allow it). A clickable link is kept in the article instead. If the video is ever deleted from Opus 2 Trainn, that link will break.
Couldn't save as PDF, can probably convert Code into PDF as needed. 

How does the script work?

  1. Checks when it last ran - it reads a file called last_sync.txt which contains a date and time. If this file doesn't exist (the very first time ever), it downloads everything from scratch. This file is saved on Global Share with the portal folders. 
  2. Logs into FreshDesk -it uses an API key (like a secret password) to connect to FreshDesk and ask for the data.
  3. Gets the list of portals -it asks FreshDesk which categories belong to each portal.
  4. Works through every category, folder, and article - like opening a filing cabinet, then each drawer, then each file inside.
    1. Will include any new categories/folders/articles. 
    2. Will not delete any articles which have been removed, need to manually do this.
    3. Will include both draft + published articles. 
  5. Checks if the article has changed - if an article hasn't been updated since the last sync, it skips it. No point saving something that hasn't changed.
  6. Downloads all images in the article - finds every image, saves it to an "Article Name - Images" folder numbered 01_, 02_, 03_ in order, and updates the article to point to your local copies.
  7. Saves the article as an HTML file - the article text gets saved as a .html file you can open in any browser. 
  8. Updates last_sync.txt - saves today's date and time so next time the script knows what's already been saved.
  9. Updates sync_log.txt - saves the log messages for the latest sync (should be same as last_sync.txt): synced / skipped / error, for each article. 

The API key — what is it and where do I find it?

An API key is like a secret password that proves to FreshDesk "yes, I'm allowed to read this data". Without it, FreshDesk won't talk to the script. 

API Key used for this is the 'Freshdesk API' account that is set up (speak to James Allnutt / Check Pendo Resource Centre). 

Keep the API key secret! Don't share the script file with the API key typed in — treat it like a password.

How does it run automatically every day?

We use a built-in Windows feature called Task Scheduler — like setting an alarm clock on your computer. It is set to run the script every day at 11:57am.

DB's PC must be switched on at 11:57am for this to work. If the PC is off or asleep, the sync won't happen that day. It will pick up any changes the next time it runs.

How do I run it manually?

The script can be run manually

  1. Open the script in VS Code - "C:\Users\dbeale\OneDrive - Opus 2 International Limited\Documents\Python\FreshDesk Back Up\FreshDesk Back Up - Final (save as html code - with updated checks and image extraction).py"
  2. Run - Terminal should show any error messages. 
    1. To run a full download of all articles, delete the last_sync.txt file before running.  

Something has gone wrong?

The sync_log.txt file logs both confirmation of sync, skipped entries as there was nothing to update since last sync and any errors. Errors should be logged in line with the following: 

What you seeWhat it meansWhat to do
Could not fetch portals. Check your API key.The API key is wrong or missingOpen the script in Notepad and check the API key is correct
⚠️ 0 images saved, 2 could not be downloadedImages failed to downloadCheck your internet connection. FreshDesk may be temporarily down.
Could not save 'Article name'A file couldn't be written to your PCCheck the Back Ups folder exists and you have permission to write to it
python is not recognizedPython is not installedDownload and install Python from python.org
ModuleNotFoundError: requestsThe requests library is not installedIn Command Prompt type: pip install requests

What needs to be installed for this to work?

  • Python - The language the script is written in. Free from python.org
  • requests - A Python add-on for talking to the internet. Install by typing "pip install requests" in Command Prompt / Terminal
  • OneDrive - Must be running and signed in so files saved to your PC automatically sync up to SharePoint
  • Your FreshDesk API key - typed into the top of the script file