Stringing together C and Python code in Go? - python

Update
I'm trying to create a simple Go function which will simply take in a string of reddit-style Markdown and return the appropriate HTML.
Right now, I know that having Discount installed is a prerequisite and that at least the following three files are used by reddit as wrappers around Discount:
https://github.com/reddit/reddit/blob/master/r2/r2/lib/c/reddit-discount-wrapper.c
https://github.com/reddit/reddit/blob/master/r2/r2/lib/c_markdown.py
https://github.com/reddit/reddit/blob/master/r2/r2/lib/py_markdown.py
Based on this, does anyone know how I can sort of glue all this together with Cgo and go-python to create a simple Markdown function? (independent of the rest of the reddit source code)

If all you want is Markdown, I don't see how Python fits into this. Maybe there's more to it, but if at all possible you should leave Python out of this. If there's a reason to use Python that wasn't in the question, I can edit this answer and address that.
First, try this native Go Markdown package: https://github.com/knieriem/markdown
If that doesn't work, the next easiest thing is to take Discount (or any other Markdown library written in C, such as GitHub's Upskirt fork) and wrap it with cgo or SWIG.

Related

Using python twitter library how can i extract the list of users follow a particular #hashtags anonymously?

So, I have a problem statement in which I want to extract the list of users who are following a particular #hashtag like #obama, #corona etc.
The challenge here is I want to extract this data anonymously i.e without providing any account keys.
I tried a library named twint that is capable of doing this but it's very slow. can anyone recommend a better alternative for my use case..?
there's no such library available that satisfy your use case. yes there's this twint library but as you mentioned it's slow for your use case. so try with some other language libraries see if something is available over there.
You can try to make a scripts in python using selenium, and I think that you could get that names of users very fast.
This Github repo which I found might be useful. It does not require authentication to get the twitter data. Have a look at it -https://github.com/bisguzar/twitter-scraper
I tried this approach last year, but found out that my date range fell well outside of the available info provided by Twitter, and had to use the Premium API. If this is not a constraint for you, and since you do not want to code your own scraper, take a look at this option:
TweetScraper: Updated in September last year, also provides MongoDB integration. I haven't tried it, but seems to work OK. Don't know about the time performance.

Use jinja for generating python class

I have a project that needs to automatically generate a python class according to some configuration files using python.
During my searches, I became familiar with Jinja2 which seems to be very popular for generating web pages, but I couldn't really find a similar case which uses Jinja to generate some python codes using Jinja (I know that it is definitely possible to do it, just the lack of examples made me hesitated).
Is it make sense to use Jinja2 for my case or is there any easier solution for generating python from python?!
You can use jinja to generate any text. I use jinja myself to generate python and there is at least one previous stack overflow post.

how can i use spellchecking in django (haystack with whoosh)?

I am working on a django website. I want to search from a lots of texts from django.models(texts is something like stackoverflow questions). I am doing search with Haystack+whoosh. It is very nice using it. Much better than django.object.filter(body_text__icontains="food")
So i would like to know whether i able to have Spelling Suggestions using whoosh or some other PUre python package available. i don't like solr(since it needs java, after every update i need to rebuild the index using java(solr))
Whoosh's documentation for version 2.4.1 indicates it does indeed have a pure-Python spelling suggestion module.

Microsoft Speech Recognition Custom Training

I have been wanting to create an application using the Microsoft Speech Recognition.
My application's users are expected to often say abbreviated things, such as 'LHC' for 'Large Hadron Collider' or 'CERN'. Given that exact order, my application will return
You said: At age C.
You said: Cern
While it did work for 'CERN', it failed very badly for 'LHC'.
However, if I could make my own custom training files, I could easily place the term 'LHC' somewhere in there. Then, I could make the user access the Speech Control Panel and run my training file.
All the links I have found for this have been frustratingly useless, as they just say things like 'This is ----, you should try going to the ---- forum instead'.
If it does help, here is a list of the links:
http://compgroups.net/comp.speech.users/add-my-own-training/153194
https://groups.google.com/forum/#!topic/microsoft.public.speech.server/v58SH1ov22s
http://social.msdn.microsoft.com/Forums/en/servercorefordevelopers/thread/f7a35f3f-b352-464a-b264-e16eb4afd049
Is my problem even possible? Or are the training files themselves in a special format? If so, can that format be reproduced?
A solution that can also work on Windows XP would be ideal.
Thanks in advance!
P.S. If there are any libraries or modules out there already for this, could anyone point me to some? A Python or C/C++ solution would be splendid. Also, since I'd rather not post another question regarding this, is it possible to utilize the train utilities from command prompt (or without the GUI visible, but still having total command of all controls)?
Okay, pulling this from a thing I wrote three or four years ago now, but I believe you want to do something like this.
The grammar library is a trained system which can recognize words. You can create your own grammar library cued to specific words.
C#, sorry
using System.Speech
using System.Speech.Recognition
using System.Speech.AudioFormat
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
string[] words = {"L H C", "CERN"};
Choices choices = new Choices(words);
GrammarBuilder gb = new GrammarBuilder(choices);
Grammar grammar = new Grammar(gb);
sre.LoadGrammar(grammar);
That is as far as I can get you. From docs it looks like you can define the pronunciations somehow. So perhaps that way you could have LHC map directly to a single word. Here are the docs on the grammar class - http://msdn.microsoft.com/en-us/library/system.speech.recognition.grammar.aspx
Small update - see example in their docs here http://msdn.microsoft.com/en-us/library/ms554228.aspx

Python pefile member question

Gang,
I apologize if this is a really dumb question... I am wanting to use the super convenient python script pefile (http://code.google.com/p/pefile/) that parses an executable and lists particular information about the PE structure. My question is where can I find information about how to access particular members of the executable? I've scoured the wiki and read the usage examples but that documentation only covered 4-5 members. What I am wondering is if you guys have a list of members I can access to display the information I care about. So specifically, if I wanted to list the Stack Commit Size of an executable, does it look like this: pe.FILE_HEADER.StackCommitSize, obviously I can run this code and figure it out but have you guys seen API DOC floating around that I find the members i need?
THANKS!
From the PE docstring:
Basic headers information will be available in the attributes:
DOS_HEADER
NT_HEADERS
FILE_HEADER
OPTIONAL_HEADER
All of them will contain among their attributes the members of the
corresponding structures as defined in WINNT.H
So, look at winnt.h and you'll see which attributes are available.
Or just read the source code for the module. It's big, but everything you need to know is in there.
You can generally find everything that is in a PE file in the Microsoft PE/COFF specification.
Once you've looked there, you know that the StackCommitSize is in the optional image header. Then all you have to do is to look for the corresponding structure in pefile, which usually bears a similar name, if not indeed the very same name. In this case:
pe = pefile.PE("C:\\Windows\\Notepad.exe")
print pe.OPTIONAL_HEADER.SizeOfStackCommit
Will give you what you want.
If you have trouble finding SizeOfStackCommit (after you've found it in the specification), just use your quick find on the source code. It's as easy to read as you can get, and I don't think you'll have any trouble finding the required structure.
Now, there probably aren't any API docs for pefile itself, but as you can see there's really no need for it, since it's just a nice Pythonic wrapper around the PE specification itself.

Categories

Resources