Sublime Text plugin API: how to get list of files in project? - sublimetext2

I'm writing a plugin for Sublime Text 2/3 that should open multiple files which names contain a certain string.
How could I get a list of the files in the project? I can't find any related API function in the docs. I can do it with Python's os.walk but it's kinda slow. On the other hand, Sublime's Ctrl+P menu is blazingly fast, but I don't know how to access its contents from my plugin.

In Sublime Text 3 API fot exists function for get files in project, but exists function project_data() which returns project related information. for files you can code like this:
project_data = sublime.active_window().project_data()
project_folder = project_data['folders'][0]['path']
# and here os.walk(project_folder )

Related

Converting several html files into one word file

I received web-service documentation in html format, but it is very unfriendly when it comes to search for a specific word. Using index file it displays list of names of each request on the left and when you click on a particular one then on the right it displays description and content of this request.
Unfortunately I have to do some mapping with web-services that we already have. When searching through CTRL + F it only goes trough the left side (list), doesn't matter if you place cursor over the description on the right, click and try to search this way too - it doesn't work.
My idea is to extract all html files that have been provided to us into one word document (this way I can go through descriptions not only trough the list of names). Unfortunately all I can reach is that these files open in separate word files (one html file per one word file). It's almost 1000 requests to be mapped and working this way is going to take forever...
So the question is: How to combine more than one html file into one word file?
There two ways to merge html files
Using Command Line
Copy all html files that you want to merge into a folder.
Navigate to that folder using terminal or command prompt.
Execute following commands
on Mac/Linux
cat *.html > output.html
on Windows :
type *.html > output.html
Using already available tools
https://www.sobolsoft.com/howtouse/combine-html-files.htm, html-merge (Windows Only)
In order to convert merged html file to a word document, read here.

Alfresco simple OCR. Extract text from PDF file and use it to start workflow

I'm using alfresco-simple-ocr with pdfsandwich and tesseract OCR. I want to get the text from a document inserted to a folder and then use the text and a pdf file in a new workflow. I've managed to do OCR extraction and how to start a workflow with a file inserted to catalogue,
but I can't get text from file and use it in the workflow. Is there a possibility to do this? Where can I start implementing that function ? Greetings, RafaƂ
You don't need any extension for that. Alfresco already integrates PDfBox that will do that for you. After, it depends of your PDF if it's a PDF containing images (so scanned documents) or if it's a PDF containing already text inside.
If you want to OCR some images, you have as well this module:
https://github.com/bchevallereau/alfresco-tesseract
When you know what you want to transform, you can look at this page where you have a javascript sample on how to call transformers:
http://docs.alfresco.com/5.2/references/dev-extension-points-content-transformer.html
You can do that as well in Java if you need.

How to automate getting a CSV file from this website?

I've never worked with web pages before and I'd like to know how best to automate the following through programming/scripting:
go to http://financials.morningstar.com/ratios/r.html?t=GMCR&region=USA&culture=en_US
invoke the 'Export to CSV' button near the top right
save this file into local directory
parse file
Part 4 doesn't need to use the same language as for 1-3 but ideally I would like to do everything in one shot using one language.
I noticed that if I hover my mouse over the button it says: javascript:exportKeyStat2CSV(); Is this a java function I could call somehow?
Any suggestions are appreciated.
It's a JavaScript function, which is not Java!
At first glance, this may seem like you need to execute Javascript to get it done, but if you look at the source of the document, you can see the function is simply implemented like this:
function exportKeyStat2CSV(){
var orderby = SRT_keyStuts.getOrderFromCookie("order");
var urlstr = "//financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNAS:GMCR&region=usa&culture=en-US&cur=&order="+orderby;
document.location = urlstr;
}
So, it builds a url, which is completely fixed, except the order by part, which is taken from a cookie. Then it simply navigates to that url by setting document.location. A small test shows you even get a csv file if you leave the order by part empty, so probably, you can just download the CSV from the base url that is in the code.
Downloading can be done using various tools, for instance WGet for Windows. See SuperUser for more possibilities. Anyway, 'step 1 to 3' is actually just a single command.
After that, you just need to parse the file. Parsing CSV files can be done using batch, and there are several examples available. I won't get into details, since you didn't provide any in your question.
PS. I'd check their terms of use before you actually implement this.
The button directs me to this link:
http://financials.morningstar.com/ajax/exportKR2CSV.html?&callback=?&t=XNAS:GMCR&region=usa&culture=en-US&cur=&order=asc
You could use the Python 3 module urllib and fetch the file, save it using the os or shutil modules, then parse it using one of the many CSV parsing modules, or by making your own.

Sublime Text 3 plugin development: access own files

The porting guide states that:
Packages in Sublime Text 3 are able to be run from .sublime-package
(i.e., renamed .zip files) files directly, in contrast to Sublime Text 2, which
unzipped them prior to running.
While in most changes this should lead to no differences, it is
important to keep this in mind if you are accessing files in your
package.
So how do I access files in my own package? My plugin comes with some static files that it must use.
You can use sublime.load_resource(name) where name is (from the API docs)
Loads the given resource. The name should be in the format Packages/Default/Main.sublime-menu.

Sublime text 2 find in folder with file extension

How do I search in a folder in sublime text 2 with file extension?
My where when I use:
*.js
searches globally for all js files.
If I try to restrict it to a folder:
/project/*.js
it matches nothing.
Instead of this:
/project/*.js
Try using this:
project .js
This should match files which have project in the path and have a .js extension
EDIT: The above assumes you're trying to find all the files with .js extension using the Goto Anything feature in Sublime Text.
In case you'd like to search within .js files located within a directory, you can add an Include Filter in the search path:
/project,*.js
This will search for the text you've entered, limiting the scope to files within /project and it's sub-directories having the extension .js.
Reference: Sublime Text Docs - Search Scope
EDIT 2: For Sublime Text 3, refer Simons answer below.
godfrzero's answer does not work in Sublime 3 as it actually includes ALL JS files plus ALL files in the project folder.
Instead, you need to specify it similar to how you had it originally...
project/*.js
Note that there's no leading slash, as that will treat it as an absolute path which you won't want in most cases. To include multiple file types within the folder, I think you need to specify it like this:
folder/*.ctp,folder/*.php
This will match any of the following files:
/app/folder/example.ctp
/app/folder/example.php
/app/folder/subfolder/example.ctp
/app/long/path/folder/subfolder/example.php
I know you asked about Sublime 2, but hopefully this helps others (like myself) who are Googling for such advice.
Simon.
My Sublime ver: 3.2.2
Adding to above answers, I was trying to find in all python files starting with test_ . so this is how I did it.
After pressing Ctrl+Shift+F, in the window.
Where : /home/WorkDir/test, test_*.py