Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created March 9, 2018 08:54
Show Gist options
  • Save m-x-k/b3369f44bf3f2dafe605aa66acf958ca to your computer and use it in GitHub Desktop.
Save m-x-k/b3369f44bf3f2dafe605aa66acf958ca to your computer and use it in GitHub Desktop.
Generate web sequence diagram example
import urllib
import re
def getSequenceDiagram(text, output_file, style ='default'):
request = {}
request["message"] = text
request["style"] = style
request["apiVersion"] = "1"
url = urllib.urlencode(request)
f = urllib.urlopen("http://www.websequencediagrams.com/", url)
line = f.readline()
f.close()
expr = re.compile("(\?(img|pdf|png|svg)=[a-zA-Z0-9]+)")
m = expr.search(line)
if m == None:
print "Invalid response from server."
return False
urllib.urlretrieve("http://www.websequencediagrams.com/" + m.group(0),
output_file)
return True
if __name__ == '__main__':
text = """
title Authentication Sequence
Alice->Bob: Authentication Request
note right of Bob: Bob thinks about it
Bob->John: Login
Bob->Alice: Authentication Response
"""
getSequenceDiagram(text, "/tmp/test.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment