Created
March 9, 2018 08:54
-
-
Save m-x-k/b3369f44bf3f2dafe605aa66acf958ca to your computer and use it in GitHub Desktop.
Generate web sequence diagram example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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